本文整理汇总了C#中System.Security.Cryptography.SHA256CryptoServiceProvider.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# SHA256CryptoServiceProvider.Clear方法的具体用法?C# SHA256CryptoServiceProvider.Clear怎么用?C# SHA256CryptoServiceProvider.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.SHA256CryptoServiceProvider
的用法示例。
在下文中一共展示了SHA256CryptoServiceProvider.Clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EncryptSHA256
public string EncryptSHA256(string textToEncrypt)
{
HashAlgorithm hasher = null;
try
{
hasher = new SHA256Managed();
}
catch
{
hasher = new SHA256CryptoServiceProvider();
}
byte[] plainBytes = System.Text.Encoding.UTF8.GetBytes(textToEncrypt);
byte[] hashedBytes = hasher.ComputeHash(plainBytes);
hasher.Clear();
return Convert.ToBase64String(hashedBytes);
}
示例2: GetHash
/// <summary>Get hash code</summary>
/// <param name="value">value to be hashed</param>
/// <returns>Hashed value</returns>
private static string GetHash(string value)
{
byte[] hash = null;
try
{
using (HashAlgorithm algorithm = new SHA256CryptoServiceProvider())
{
if (value.Length > HashModifier.Length)
value += ReverseString(HashModifier);
else
value += ReverseString(HashModifier.Substring(1, value.Length));
hash = Encoding.Unicode.GetBytes(value);
for (var i = 0; i < 1000; i++)
{
hash = algorithm.ComputeHash(hash);
}
algorithm.Clear();
}
}
catch (Exception ex)
{
var message = ex.Message;
}
var hashed = StripCharacters(Convert.ToBase64String(hash));
return hashed;
}
示例3: 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;
}