本文整理汇总了C#中System.Security.Cryptography.SHA384Managed.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# SHA384Managed.Dispose方法的具体用法?C# SHA384Managed.Dispose怎么用?C# SHA384Managed.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.SHA384Managed
的用法示例。
在下文中一共展示了SHA384Managed.Dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ComputeHash
public static string ComputeHash(string plaintext, Supported_HA hash, byte[] salt)
{
int minSaltLength = 4;
int maxSaltLenght = 6;
byte[] SaltBytes = null;
if(salt!=null)
{
SaltBytes = salt;
}
else
{
Random r = new Random();
int SaltLenght = r.Next(minSaltLength, maxSaltLenght);
SaltBytes = new byte[SaltLenght];
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
rng.GetNonZeroBytes(SaltBytes);
rng.Dispose();
}
byte[] plaintData = ASCIIEncoding.UTF8.GetBytes(plaintext);
byte[] plainDataAndSalt = new byte[plaintData.Length + SaltBytes.Length];
for(int x=0; x<plaintData.Length;x++)
{
plainDataAndSalt[x] = plaintData[x];
}
for (int n = 0; n < SaltBytes.Length; n++)
plainDataAndSalt[plaintData.Length + n] = SaltBytes[n];
byte[] hashValue = null;
switch(hash)
{
case Supported_HA.SHA256:
SHA256Managed sha= new SHA256Managed();
hashValue= sha.ComputeHash(plainDataAndSalt);
sha.Dispose();
break;
case Supported_HA.SHA384:
SHA384Managed sha1 = new SHA384Managed();
hashValue = sha1.ComputeHash(plainDataAndSalt);
sha1.Dispose();
break;
case Supported_HA.SHA512:
SHA512Managed sha2 = new SHA512Managed();
hashValue = sha2.ComputeHash(plainDataAndSalt);
sha2.Dispose();
break;
}
byte[] resuflt = new byte[hashValue.Length + SaltBytes.Length];
for (int x = 0; x < hashValue.Length; x++)
resuflt[x] = hashValue[x];
for (int n = 0; n < SaltBytes.Length; n++)
resuflt[hashValue.Length + n] = SaltBytes[n];
return Convert.ToBase64String(resuflt);
}