本文整理汇总了C#中System.Security.Cryptography.HMACSHA512.ComputeHash方法的典型用法代码示例。如果您正苦于以下问题:C# HMACSHA512.ComputeHash方法的具体用法?C# HMACSHA512.ComputeHash怎么用?C# HMACSHA512.ComputeHash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.HMACSHA512
的用法示例。
在下文中一共展示了HMACSHA512.ComputeHash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CryptoSHA512
public static string CryptoSHA512(string TextToCryptograph)
{
var sha512 = new HMACSHA512();
byte[] passwordArray = System.Text.Encoding.Default.GetBytes(TextToCryptograph);
return Convert.ToBase64String(sha512.ComputeHash(passwordArray));
}
示例2: HMACSHA512
public static byte[] HMACSHA512(byte[] key, byte[] data)
{
using (var hmac = new HMACSHA512(key))
{
return hmac.ComputeHash(data);
}
}
示例3: SignFile
// Computes a keyed hash for a source file and creates a target file with the keyed hash
// prepended to the contents of the source file.
public static void SignFile(byte[] key, String sourceFile, String destFile)
{
// Initialize the keyed hash object.
using (HMACSHA512 hmac = new HMACSHA512(key))
{
using (FileStream inStream = new FileStream(sourceFile, FileMode.Open))
{
using (FileStream outStream = new FileStream(destFile, FileMode.Create))
{
// Compute the hash of the input file.
byte[] hashValue = hmac.ComputeHash(inStream);
// Reset inStream to the beginning of the file.
inStream.Position = 0;
// Write the computed hash value to the output file.
outStream.Write(hashValue, 0, hashValue.Length);
// Copy the contents of the sourceFile to the destFile.
int bytesRead;
// read 1K at a time
byte[] buffer = new byte[1024];
do
{
// Read from the wrapping CryptoStream.
bytesRead = inStream.Read(buffer, 0, 1024);
outStream.Write(buffer, 0, bytesRead);
} while (bytesRead > 0);
}
}
}
}
示例4: JsonWebToken
static JsonWebToken()
{
HashAlgorithms = new Dictionary<JwtHashAlgorithm, Func<byte[], byte[], byte[]>>
{
{JwtHashAlgorithm.RS256, (key, value) =>
{
using (var sha = new HMACSHA256(key))
{
return sha.ComputeHash(value);
}
}
},
{JwtHashAlgorithm.HS384, (key, value) =>
{
using (var sha = new HMACSHA384(key))
{
return sha.ComputeHash(value);
}
}
},
{JwtHashAlgorithm.HS512, (key, value) =>
{
using (var sha = new HMACSHA512(key))
{
return sha.ComputeHash(value);
}
}
}
};
}
示例5: Hash
public byte[] Hash(byte[] key, byte[] plainText)
{
using (var hmac = new HMACSHA512(key))
{
return hmac.ComputeHash(plainText);
}
}
示例6: Encode
public static string Encode(string publicKey, int choice = 2)
{
byte[] hashMessage = null;
byte[] messageBytes = m_encoding.GetBytes(publicKey);
switch (choice%6)
{
case 0:
var hmacmd5 = new HMACMD5(m_keyBytes);
hashMessage = hmacmd5.ComputeHash(messageBytes);
break;
case 1:
var hmacripedmd160 = new HMACRIPEMD160(m_keyBytes);
hashMessage = hmacripedmd160.ComputeHash(messageBytes);
break;
case 2:
var hmacsha1 = new HMACSHA1(m_keyBytes);
hashMessage = hmacsha1.ComputeHash(messageBytes);
break;
case 3:
var hmacsha256 = new HMACSHA256(m_keyBytes);
hashMessage = hmacsha256.ComputeHash(messageBytes);
break;
case 4:
var hmacsha384 = new HMACSHA384(m_keyBytes);
hashMessage = hmacsha384.ComputeHash(messageBytes);
break;
case 5:
var hmacsha512 = new HMACSHA512(m_keyBytes);
hashMessage = hmacsha512.ComputeHash(messageBytes);
break;
}
return Convert.ToBase64String(hashMessage);
}
示例7: ComputeSHA
public static string ComputeSHA(string str, string key)
{
byte[] passwordBytes = ASCIIEncoding.ASCII.GetBytes(str);
byte[] saltBytes = ASCIIEncoding.ASCII.GetBytes(key);
var crypt = new HMACSHA512(saltBytes);
return BitConverter.ToString(crypt.ComputeHash(passwordBytes)).Replace("-", "");
}
示例8: HashingAMessageWithASecretKey
public byte[] HashingAMessageWithASecretKey(byte[] iterationNumberByte, byte[] userIdByte)
{
using (var hmac = new HMACSHA512(userIdByte))
{
byte[] hash = hmac.ComputeHash(iterationNumberByte);
return hash;
}
}
示例9: getHash
private static byte[] getHash(byte[] keyByte, byte[] messageBytes)
{
using (var hmacsha512 = new HMACSHA512(keyByte))
{
Byte[] result = hmacsha512.ComputeHash(messageBytes);
return result;
}
}
示例10: GenerateSHA512Signature
public string GenerateSHA512Signature(FormUrlEncodedContent request)
{
HMAC digester = new HMACSHA512(this.PrivateKeyBytes);
StringBuilder hex = new StringBuilder();
byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(request.ReadAsStringAsync().Result);
return BitConverter.ToString(digester.ComputeHash(requestBytes)).Replace("-", "").ToLower();
}
示例11: Generate
public string Generate(string password)
{
byte[] msgByte = ASCIIEncoding.ASCII.GetBytes(password);
HMACSHA512 hmac = new HMACSHA512();
byte[] hashMsg = hmac.ComputeHash(msgByte);
return HttpServerUtility.UrlTokenEncode(hashMsg);
}
示例12: ComputeMacSha512
/// <summary>
/// Computes the mac sha512.
/// </summary>
/// <param name="storageKey">The storage key.</param>
/// <param name="canonicalizedString">The canonicalized string.</param>
/// <returns>The computed hash.</returns>
internal static string ComputeMacSha512(StorageKey storageKey, string canonicalizedString)
{
byte[] dataToMAC = Encoding.UTF8.GetBytes(canonicalizedString);
using (HMACSHA512 hmacsha1 = new HMACSHA512(storageKey.Key))
{
return System.Convert.ToBase64String(hmacsha1.ComputeHash(dataToMAC));
}
}
示例13: Hash
public byte[] Hash(byte[] clearBytes)
{
using (var hmac = new HMACSHA512(_key))
{
hmac.Initialize();
byte[] hashBytes = hmac.ComputeHash(clearBytes);
return hashBytes;
}
}
示例14: Sign
public static String Sign(HttpRequestMessage request, String secretKey)
{
String message = BuildMessage(request);
HMACSHA512 hmac = new HMACSHA512(Convert.FromBase64String(secretKey));
byte[] signature = hmac.ComputeHash(encoding.GetBytes(message));
return Convert.ToBase64String(signature);
}
示例15: SignString512
public static string SignString512(string stringToSign, string secretKey)
{
byte[] secretkeyBytes = Convert.FromBase64String(secretKey);
byte[] inputBytes = Encoding.UTF8.GetBytes(stringToSign);
using (var hmac = new HMACSHA512(secretkeyBytes))
{
byte[] hashValue = hmac.ComputeHash(inputBytes);
return System.Convert.ToBase64String(hashValue);
}
}