本文整理汇总了C#中System.Security.Cryptography.SHA256CryptoServiceProvider.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# SHA256CryptoServiceProvider.Dispose方法的具体用法?C# SHA256CryptoServiceProvider.Dispose怎么用?C# SHA256CryptoServiceProvider.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.SHA256CryptoServiceProvider
的用法示例。
在下文中一共展示了SHA256CryptoServiceProvider.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HashPassword
private NewPassword HashPassword(NewPassword np)
{
HashAlgorithm hashAlg = null;
try
{
hashAlg = new SHA256CryptoServiceProvider();
byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(np.GetSaltPassword());
byte[] bytHash = hashAlg.ComputeHash(bytValue);
np.SaltedHashedPassword = Convert.ToBase64String(bytHash);
}
catch (Exception e)
{
throw e;
}
finally
{
if (hashAlg != null)
{
hashAlg.Clear();
hashAlg.Dispose();
hashAlg = null;
}
}
return np;
}
示例2: GenerateKey
static byte[] GenerateKey(string RawKey)
{
byte[] WhatToReturn;
SHA512CryptoServiceProvider SCSP = new SHA512CryptoServiceProvider();
SHA256CryptoServiceProvider SCSP256 = new SHA256CryptoServiceProvider();
//Whatever the key is... hash it once.
byte[] ReturnBytes = SCSP.ComputeHash(UnicodeEncoding.ASCII.GetBytes(RawKey.ToCharArray()));
//Rehash the key up to 256 times depending on what key the user chose.
WhatToReturn = ReturnBytes;
for (byte x = 0; x <= ReturnBytes[0]; x++)
WhatToReturn = SCSP.ComputeHash(WhatToReturn);
//Make sure the key size is 32 bytes.
WhatToReturn = SCSP256.ComputeHash(WhatToReturn);
SCSP.Dispose();
SCSP256.Dispose();
//DISPOSE ALL SENSITIVE DATA
Random rd = new Random();
rd.NextBytes(ReturnBytes);
rd = null;
GC.Collect();
//Finish
return WhatToReturn;
}