本文整理汇总了C#中UTF8Encoding.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# UTF8Encoding.GetBytes方法的具体用法?C# UTF8Encoding.GetBytes怎么用?C# UTF8Encoding.GetBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UTF8Encoding
的用法示例。
在下文中一共展示了UTF8Encoding.GetBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Encrypt
// Token: 0x06000EF7 RID: 3831 RVA: 0x00045348 File Offset: 0x00043548
public static string Encrypt(string unencrypted)
{
RijndaelManaged rijndaelManaged = new RijndaelManaged();
ICryptoTransform encryptor = rijndaelManaged.CreateEncryptor(SimpleAES.key, SimpleAES.vector);
UTF8Encoding uTF8Encoding = new UTF8Encoding();
return Convert.ToBase64String(SimpleAES.Encrypt(uTF8Encoding.GetBytes(unencrypted), encryptor));
}
示例2: In
public void In(
[FriendlyName("Key", "The string to be used to generate the hash from.")]
string Key,
[FriendlyName("SHA1 Hash", "The SHA1 Hash generated by the Key.")]
out string Hash
)
{
if (Key != "")
{
UTF8Encoding ue = new UTF8Encoding();
byte[] bytes = ue.GetBytes(Key);
// encrypt bytes
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
byte[] hashBytes = sha1.ComputeHash(bytes);
// Convert the encrypted bytes back to a string (base 16)
string tmpHash = "";
for (int i = 0; i < hashBytes.Length; i++)
{
tmpHash += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
}
Hash = tmpHash.PadLeft(32, '0');
}
else
{
uScriptDebug.Log("[Generate SHA1 Hash] The Key provided was empty, returning an empty string for the SHA1 Hash.", uScriptDebug.Type.Warning);
Hash = "";
}
}
示例3: In
public void In(
[FriendlyName("Key", "The string to be used to check against the provided SHA1 hash.")]
string Key,
[FriendlyName("SHA1 Hash", "The SHA1 Hash to check the key against.")]
string Hash
)
{
if (Key != "" && Hash != "")
{
UTF8Encoding ue = new UTF8Encoding();
byte[] bytes = ue.GetBytes(Key);
// encrypt bytes
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
byte[] hashBytes = sha1.ComputeHash(bytes);
// Convert the encrypted bytes back to a string (base 16)
string tmpHash = "";
for (int i = 0; i < hashBytes.Length; i++)
{
tmpHash += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
}
string finalHash = tmpHash.PadLeft(32, '0');
if (finalHash == Hash)
{
m_GoodHash = true;
}
}
}
示例4: get_uft8
public static string get_uft8(string unicodeString)
{
UTF8Encoding utf8 = new UTF8Encoding();
byte[] encodedBytes = utf8.GetBytes(unicodeString);
string decodedString = utf8.GetString(encodedBytes);
return decodedString;
}
示例5: PosTest2
public bool PosTest2()
{
bool retVal = true;
// Add your scenario description here
TestLibrary.TestFramework.BeginScenario("PosTest2: Verify method GetBytes(String,Int32,Int32,Byte[],Int32) with null chars");
try
{
Byte[] bytes;
String chars = "";
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = chars.Length;
bytes = new Byte[byteCount];
int bytesEncodedCount = utf8.GetBytes(chars, 0, byteCount, bytes, 0);
if (bytesEncodedCount != 0)
{
TestLibrary.TestFramework.LogError("002.1", "Method GetBytes Err.");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002.2", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例6: PosTest1
public bool PosTest1()
{
bool retVal = true;
// Add your scenario description here
TestLibrary.TestFramework.BeginScenario("PosTest1: Verify method GetBytes(Char[],Int32,Int32,Byte[],Int32) with non-null chars");
try
{
Byte[] bytes;
Char[] chars = new Char[] {
'\u0023',
'\u0025',
'\u03a0',
'\u03a3' };
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars, 1, 2);
bytes = new Byte[byteCount];
int bytesEncodedCount = utf8.GetBytes(chars, 1, 2, bytes, 0);
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("001", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例7: ToDataSet
public static DataSet ToDataSet(DataSetData dsd)
{
DataSet ds = new DataSet();
UTF8Encoding encoding = new UTF8Encoding();
Byte[] byteArray = encoding.GetBytes(dsd.DataXML);
MemoryStream stream = new MemoryStream(byteArray);
XmlReader reader = new XmlTextReader(stream);
ds.ReadXml(reader);
XDocument xd = XDocument.Parse(dsd.DataXML);
foreach (DataTable dt in ds.Tables)
{
var rs = from row in xd.Descendants(dt.TableName)
select row;
int i = 0;
foreach (var r in rs)
{
DataRowState state = (DataRowState)Enum.Parse(typeof(DataRowState), r.Attribute("RowState").Value);
DataRow dr = dt.Rows[i];
dr.AcceptChanges();
if (state == DataRowState.Deleted)
dr.Delete();
else if (state == DataRowState.Added)
dr.SetAdded();
else if (state == DataRowState.Modified)
dr.SetModified();
i++;
}
}
return ds;
}
示例8: CompleteTag
/// <summary>
/// Main constructor of the Tag. This reads information from the given filename and initializes all fields of the tag.
/// It's important to know that this constructor has a considerable weight in term of processor time because it calculates two SHA1 hash:
/// one for the entire file and one for the relevant tag information.
/// </summary>
/// <param name="filename">Filename from whom extract the information for the tag</param>
public CompleteTag(string filename)
{
byte[] retVal;
SHA1 crypto = new SHA1CryptoServiceProvider();
using (FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
{
retVal = crypto.ComputeHash(file);
file.Close();
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < retVal.Length; i++)
{
sb.Append(retVal[i].ToString("x2"));
}
this.FileHash= sb.ToString();
this.FillTag(filename);
System.Text.UTF8Encoding enc= new UTF8Encoding();
byte[] tHashByte = crypto.ComputeHash(enc.GetBytes(this.contentString()));
crypto.ComputeHash(tHashByte);
sb.Clear();
for (int i = 0; i < tHashByte.Length; i++)
{
sb.Append(tHashByte[i].ToString("x2"));
}
this.TagHash = sb.ToString();
}
示例9: Post
public virtual void Post(string url, Dictionary<string, string> data, System.Action<HttpResult> onResult) {
this.MakeRequest(url, HttpMethods.POST, onResult, (r) => {
JSONObject js = new JSONObject(data);
var requestPayload = js.ToString();
UTF8Encoding encoding = new UTF8Encoding();
r.ContentLength = encoding.GetByteCount(requestPayload);
r.Credentials = CredentialCache.DefaultCredentials;
r.Accept = "application/json";
r.ContentType = "application/json";
//Write the payload to the request body.
using ( Stream requestStream = r.GetRequestStream())
{
requestStream.Write(encoding.GetBytes(requestPayload), 0,
encoding.GetByteCount(requestPayload));
}
return false;
});
}
示例10: AesEncryptor
static AesEncryptor()
{
encoder = new UTF8Encoding();
RijndaelManaged rijndaelManaged = new RijndaelManaged();
rijndaelManaged.Key = encoder.GetBytes(keyString).Take(keySize).ToArray();
rijndael = rijndaelManaged;
rijndael.BlockSize = 128;
}
示例11: HashMD5
public static string HashMD5(string phrase)
{
if (phrase == null)
return null;
var encoder = new UTF8Encoding();
var md5Hasher = new MD5CryptoServiceProvider();
var hashedDataBytes = md5Hasher.ComputeHash(encoder.GetBytes(phrase));
return ByteArrayToHexString(hashedDataBytes);
}
示例12: PosTest1
public void PosTest1()
{
Byte[] bytes;
String chars = "UTF8 Encoding Example";
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = chars.Length;
bytes = new Byte[byteCount];
int bytesEncodedCount = utf8.GetBytes(chars, 1, 2, bytes, 0);
}
示例13: EncryptRSA
public static byte[] EncryptRSA(string publicKeyAsPem, string payload, string passphrase = null)
{
var encoder = new UTF8Encoding();
byte[] byte_payload = encoder.GetBytes(payload);
CryptoKey d = CryptoKey.FromPublicKey(publicKeyAsPem, passphrase);
OpenSSL.Crypto.RSA rsa = d.GetRSA();
byte[] result = rsa.PublicEncrypt(byte_payload, OpenSSL.Crypto.RSA.Padding.PKCS1);
rsa.Dispose();
return result;
}
示例14: ImageButton1_Click
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
try
{
if (txtNewPass.Text!="" && txtNewPassRepeat.Text!="")
{
Literal1.Text = "";
var query1 = context.ForgotPasswords.Where(v => v.VerificationCode == VCod).FirstOrDefault();
int UserId = query1.UserId;
var query = context.Users.Where(u => u.UserId == UserId).SingleOrDefault();
string NewPass = txtNewPass.Text;
string RpNewPass = txtNewPassRepeat.Text;
MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
Byte[] hashedBytes;
UTF8Encoding encoder = new UTF8Encoding();
hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(NewPass));
if (NewPass == RpNewPass)
{
query.Password = hashedBytes;
context.SubmitChanges();
context.ForgotPasswords.DeleteOnSubmit(query1);
context.SubmitChanges();
lblsucces.Visible = true;
Imageok.Visible = true;
}
else
{
Literal1.Text = "<p class='FormValidation'>کلمه عبور و تکرار آن را وارد نمایید!</p>";
}
}
}
catch (Exception)
{
Response.Redirect("~/Default.aspx");
}
}
示例15: NegTest2
public void NegTest2()
{
Byte[] bytes;
String chars = "UTF8 Encoding Example";
UTF8Encoding utf8 = new UTF8Encoding();
bytes = null;
Assert.Throws<ArgumentNullException>(() =>
{
int bytesEncodedCount = utf8.GetBytes(chars, 1, 2, bytes, 0);
});
}