本文整理汇总了C#中System.Text.UTF8Encoding.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# System.Text.UTF8Encoding.GetBytes方法的具体用法?C# System.Text.UTF8Encoding.GetBytes怎么用?C# System.Text.UTF8Encoding.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.UTF8Encoding
的用法示例。
在下文中一共展示了System.Text.UTF8Encoding.GetBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestIssuerSetupParameters
public void TestIssuerSetupParameters()
{
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
byte[][] A = new byte[][] { encoding.GetBytes("attribute value") };
byte[] TI = encoding.GetBytes("TI value");
IssuerSetupParameters isp = new IssuerSetupParameters();
isp.GroupConstruction = GroupType.Subgroup;
isp.UidP = encoding.GetBytes("UIDP value");
isp.E = new byte[] { 1 };
IssuerKeyAndParameters ikap = isp.Generate();
ikap.IssuerParameters.Verify();
// invalidate the issuer parameters
IssuerParameters ip = ikap.IssuerParameters;
SubgroupGroupElement sgG0 = (SubgroupGroupElement) ip.G[0];
byte[] g0Bytes = ip.G[0].GetEncoded();
g0Bytes[g0Bytes.Length - 1]++;
ip.G[0] = (SubgroupGroupElement) ip.Gq.CreateGroupElement(g0Bytes);
try
{
ip.Verify();
Assert.Fail();
}
catch (InvalidUProveArtifactException) { }
}
示例2: buildSignature
private static string buildSignature(NameValueCollection queryString)
{
try
{
//// The HMAC secret as configured in the skin
string hmacSecret = Globals.Instance.settings["PayPalhmacSecret"];
//// Generate the signing string
string signingString = queryString["paymentAmount"] + queryString["currencyCode"] +
queryString["shipBeforeDate"] + queryString["merchantReference"] +
queryString["skinCode"] + queryString["merchantAccount"] +
queryString["sessionValidity"] + queryString["allowedMethods"] + queryString["merchantReturnData"];
//// Values are always transferred using UTF-8 encoding
var encoding = new System.Text.UTF8Encoding();
//// Calculate the HMAC
var myhmacsha1 = new HMACSHA1(encoding.GetBytes(hmacSecret));
return Convert.ToBase64String(myhmacsha1.ComputeHash(encoding.GetBytes(signingString)));
}
catch (Exception exp)
{
log.Error(exp);
throw;
}
}
示例3: EncryptString
/// <summary>
/// EncryptString
/// </summary>
/// <param name="message"></param>
/// <param name="passphrase"></param>
/// <returns></returns>
public static string EncryptString(string message)
{
byte[] results;
var utf8 = new System.Text.UTF8Encoding();
var hashProvider = new MD5CryptoServiceProvider();
var tdesKey = hashProvider.ComputeHash(utf8.GetBytes(Pass));
var tdesAlgorithm = new TripleDESCryptoServiceProvider
{
Key = tdesKey,
Mode = CipherMode.ECB,
Padding = PaddingMode.PKCS7
};
var dataToEncrypt = utf8.GetBytes(message);
try
{
var encryptor = tdesAlgorithm.CreateEncryptor();
results = encryptor.TransformFinalBlock(dataToEncrypt, 0, dataToEncrypt.Length);
}
finally
{
tdesAlgorithm.Clear();
hashProvider.Clear();
}
return Convert.ToBase64String(results);
}
示例4: MakeRequest
public void MakeRequest(string type, string platform, string reqjsondata)
{
System.Text.UTF8Encoding en = new System.Text.UTF8Encoding();
string secret = Configs.Secret;
string uri = "http://api.bf3stats.com/" + platform + "/" + type + "/";
WebClient wc = new WebClient();
wc.Headers["Content-Type"] = "application/x-www-form-urlencoded";
if (type == "setupkey")
{
wc.UploadStringCompleted += new UploadStringCompletedEventHandler(completed_register);
}
else
{
wc.UploadStringCompleted += new UploadStringCompletedEventHandler(completed_update);
secret = Configs.GetAPIkey();
}
System.Security.Cryptography.HMACSHA256 hmac = new System.Security.Cryptography.HMACSHA256(en.GetBytes(secret));
Byte[] bytes = en.GetBytes(reqjsondata);
string encodedRequest = Convert.ToBase64String(bytes).Replace('+', '-').Replace('/', '_').Replace("=", "");
byte[] hashVal = hmac.ComputeHash(en.GetBytes(encodedRequest));
string signature = Convert.ToBase64String(hashVal).Replace('+', '-').Replace('/', '_').Replace("=", "");
string query = "data=" + encodedRequest + "&sig=" + signature;
wc.UploadStringAsync(new Uri(uri), "POST", query);
}
示例5: Encrypt
/// encrypt a string message using a secret key that is known to both sender and recipient only;
/// need to give the initialization vector to the recipient as well;
static public bool Encrypt(byte[] ASecretKey, string AMessage, out string AEncryptedMessage, out string AInitializationVector)
{
Rijndael alg = new RijndaelManaged();
alg.Key = ASecretKey;
alg.GenerateIV();
MemoryStream ms = new MemoryStream();
CryptoStream encryptStream = new CryptoStream(
ms,
alg.CreateEncryptor(),
CryptoStreamMode.Write);
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
byte[] toEncryptBytes = enc.GetBytes(AMessage);
encryptStream.Write(toEncryptBytes, 0, toEncryptBytes.Length);
encryptStream.Close();
AEncryptedMessage = Convert.ToBase64String(ms.ToArray());
AInitializationVector = Convert.ToBase64String(alg.IV);
return true;
}
示例6: ComputeHashString
protected string ComputeHashString(string rawString)
{
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
SHA256 hashM = new SHA256Managed();
return encoding.GetString(hashM.ComputeHash(encoding.GetBytes(rawString))).
Replace(',', '.').Replace('\r', '.').Replace('\n', '.');
}
示例7: CompressContent
/// <summary>
/// Compress an string using ZIP
/// </summary>
/// <param name="xml"></param>
/// <returns></returns>
public static byte[] CompressContent(string contentToZip)
{
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
byte[] buff = encoding.GetBytes(contentToZip);
try
{
using (MemoryStream stream = new MemoryStream())
{
using (ZipOutputStream zipout = new ZipOutputStream(stream))
{
zipout.SetLevel(9);
ZipEntry entry = new ZipEntry("zipfile.zip");
entry.DateTime = DateTime.Now;
zipout.PutNextEntry(entry);
zipout.Write(buff, 0, buff.Length);
zipout.Finish();
byte[] outputbyte = new byte[(int)stream.Length];
stream.Position = 0;
stream.Read(outputbyte, 0, (int)stream.Length);
return outputbyte;
}
}
}
catch (Exception ex)
{
ex.Message.ToString();
return null;
}
}
示例8: getHash
private string getHash(string s)
{
var csp = new System.Security.Cryptography.SHA256Managed();
var utf8Encoding = new System.Text.UTF8Encoding();
byte[] result = csp.ComputeHash(utf8Encoding.GetBytes(s));
return Convert.ToBase64String(result)+"\n";
}
示例9: WriteLongString
public void WriteLongString(string str)
{
var encoding = new System.Text.UTF8Encoding();
var bytes = encoding.GetBytes(str);
WriteInt32(bytes.Length);
_base.Write(bytes);
}
示例10: EncryptData
/// <summary>
/// MD5 Hash
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
private static byte[] EncryptData(string data)
{
var md5Hasher = new System.Security.Cryptography.MD5CryptoServiceProvider();
var encoder = new System.Text.UTF8Encoding();
var hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(data));
return hashedBytes;
}
示例11: encryptData
public static byte[] encryptData(string data)
{
System.Security.Cryptography.MD5CryptoServiceProvider md5Hasher = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] hashedBytes;
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(data));
return hashedBytes;
}
示例12: StrToByteArray
public static byte[] StrToByteArray(string str)
{
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
byte[] s = encoding.GetBytes(str);
byte[] r = new byte[s.Length + 1]; // null terminator
for (int i = 0; i < s.Length; i++) { r[i] = s[i]; }
return r;
}
示例13: LoadBytes
public static X509Certificate2 LoadBytes(string certificate)
{
if (string.IsNullOrWhiteSpace(certificate))
throw new ArgumentNullException("certificate");
var encoding = new System.Text.UTF8Encoding();
return new X509Certificate2(encoding.GetBytes(certificate));
}
示例14: ComputeHash
public string ComputeHash(string str)
{
var md5 = MD5.Create();
var encoding = new System.Text.UTF8Encoding();
var encodedString = encoding.GetBytes(str);
var hashBytes = md5.ComputeHash(encodedString);
var deEncodedHash = encoding.GetChars(hashBytes);
return new string(deEncodedHash);
}
示例15: WriteString
public void WriteString(String value)
{
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
byte[] b = encoding.GetBytes(value);
WriteInt32(b.Length); //Write the String length
WriteBytes(b);
}