本文整理汇总了C#中System.Security.Cryptography.SHA1CryptoServiceProvider.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# System.Security.Cryptography.SHA1CryptoServiceProvider.Clear方法的具体用法?C# System.Security.Cryptography.SHA1CryptoServiceProvider.Clear怎么用?C# System.Security.Cryptography.SHA1CryptoServiceProvider.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.SHA1CryptoServiceProvider
的用法示例。
在下文中一共展示了System.Security.Cryptography.SHA1CryptoServiceProvider.Clear方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EncryptToSHA1
public string EncryptToSHA1(string str)
{
System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] str1 = System.Text.Encoding.UTF8.GetBytes(str);
byte[] str2 = sha1.ComputeHash(str1);
sha1.Clear();
(sha1 as IDisposable).Dispose();
return Convert.ToBase64String(str2);
}
示例2: Encriptar
public static string Encriptar(string valor)
{
string clave;
System.Security.Cryptography.SHA1CryptoServiceProvider provider = new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(valor);
byte[] inArray = provider.ComputeHash(bytes);
provider.Clear();
clave = Convert.ToBase64String(inArray);
return clave;
}
示例3: encrypt
/// <summary>
/// Método para encriptar un string. En este caso se usa para el Pass.
/// </summary>
/// <param name="password">Contraseña a encriptar</param>
/// <returns>Cadena encriptada</returns>
private static string encrypt(string password)
{
System.Security.Cryptography.HashAlgorithm hashValue = new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(password);
byte[] byteHash = hashValue.ComputeHash(bytes);
hashValue.Clear();
return (Convert.ToBase64String(byteHash));
}
示例4: SHA1_Real
public static string SHA1_Real(string data)
{
// Hash the input string using SHA1 and output a hexadecimal answer
byte[] bdata = System.Text.ASCIIEncoding.ASCII.GetBytes(data);
byte[] result = null;
System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
result = sha.ComputeHash(bdata);
sha.Clear();
string result_s = "";
foreach(byte b in result)
result_s += String.Format("{0:x2}", b);
return result_s;
}
示例5: SHA1
public static string SHA1(string data)
{
// Hash the input string using SHA1 and output a base64 answer
byte[] bdata = System.Text.ASCIIEncoding.ASCII.GetBytes(data);
byte[] result = null;
System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
result = sha.ComputeHash(bdata);
sha.Clear();
return Convert.ToBase64String(result);
}
示例6: Hash_SHA_1
/// <summary>
/// 计算SHA-1码
/// </summary>
/// <param name="word">字符串</param>
/// <param name="toUpper">返回哈希值格式 true:英文大写,false:英文小写</param>
/// <returns></returns>
public static string Hash_SHA_1(string word, bool toUpper = true)
{
try
{
System.Security.Cryptography.SHA1CryptoServiceProvider SHA1CSP
= new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(word);
byte[] bytHash = SHA1CSP.ComputeHash(bytValue);
SHA1CSP.Clear();
//根据计算得到的Hash码翻译为SHA-1码
string sHash = "", sTemp = "";
for (int counter = 0; counter < bytHash.Count(); counter++)
{
long i = bytHash[counter] / 16;
if (i > 9)
{
sTemp = ((char)(i - 10 + 0x41)).ToString();
}
else
{
sTemp = ((char)(i + 0x30)).ToString();
}
i = bytHash[counter] % 16;
if (i > 9)
{
sTemp += ((char)(i - 10 + 0x41)).ToString();
}
else
{
sTemp += ((char)(i + 0x30)).ToString();
}
sHash += sTemp;
}
//根据大小写规则决定返回的字符串
return toUpper ? sHash : sHash.ToLower();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}