本文整理汇总了C#中System.Security.Cryptography.HMACSHA512类的典型用法代码示例。如果您正苦于以下问题:C# HMACSHA512类的具体用法?C# HMACSHA512怎么用?C# HMACSHA512使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HMACSHA512类属于System.Security.Cryptography命名空间,在下文中一共展示了HMACSHA512类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAlgorithmByFunctionName
/// <summary>
/// Every time is created new instance of class to guarantee thread safety
/// </summary>
/// <param name="function"></param>
/// <returns></returns>
private HMAC GetAlgorithmByFunctionName(string function)
{
HMAC a;
switch(Util.Convertion.EnumNameToValue<HMACFunction>(function))
{
case HMACFunction.HMACMD5:
a = new HMACMD5();
break;
case HMACFunction.HMACSHA1:
a = new HMACSHA1();
break;
case HMACFunction.HMACSHA256:
a = new HMACSHA256();
break;
case HMACFunction.HMACSHA384:
a = new HMACSHA384();
break;
case HMACFunction.HMACSHA512:
a = new HMACSHA512();
break;
default:
throw new ArgumentException("Unknown function", "function");
}
return a;
}
示例2: 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);
}
}
}
};
}
示例3: BtceApi
public BtceApi(string key, string secret, string exchangeHost = null)
{
this.key = key;
hashMaker = new HMACSHA512(Encoding.ASCII.GetBytes(secret));
nonce = UnixTime.Now;
this.instanseExchangeHost = exchangeHost ?? ExchangeHost;
}
示例4: 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);
}
示例5: HMACSHA512
public static byte[] HMACSHA512(byte[] key, byte[] data)
{
using (var hmac = new HMACSHA512(key))
{
return hmac.ComputeHash(data);
}
}
示例6: Rfc2898DeriveBytes_HMACSHA512
public Rfc2898DeriveBytes_HMACSHA512(byte[] password, byte[] salt, int iterations)
{
Salt = salt;
IterationCount = iterations;
_hmacsha512 = new HMACSHA512(password);
Initialize();
}
示例7: 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);
}
}
}
}
示例8: 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));
}
示例9: Hash
public byte[] Hash(byte[] key, byte[] plainText)
{
using (var hmac = new HMACSHA512(key))
{
return hmac.ComputeHash(plainText);
}
}
示例10: HashingAMessageWithASecretKey
public byte[] HashingAMessageWithASecretKey(byte[] iterationNumberByte, byte[] userIdByte)
{
using (var hmac = new HMACSHA512(userIdByte))
{
byte[] hash = hmac.ComputeHash(iterationNumberByte);
return hash;
}
}
示例11: BtceApi
public BtceApi(string key, string secret)
{
this.key = key;
foreach (var b in Encoding.ASCII.GetBytes(secret))
Console.Write(b);
hashMaker = new HMACSHA512(Encoding.ASCII.GetBytes(secret));
nonce = UnixTime.Now;
}
示例12: 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();
}
示例13: SetUp
public override void SetUp ()
{
algo = new HMACSHA512 ();
algo.Key = new byte [8];
hash = algo;
// http://blogs.msdn.com/shawnfa/archive/2007/01/31/please-do-not-use-the-net-2-0-hmacsha512-and-hmacsha384-classes.aspx
legacy = (new HS512 ().BlockSize == 64);
}
示例14: getHash
private static byte[] getHash(byte[] keyByte, byte[] messageBytes)
{
using (var hmacsha512 = new HMACSHA512(keyByte))
{
Byte[] result = hmacsha512.ComputeHash(messageBytes);
return result;
}
}
示例15: 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("-", "");
}