using System.Text;
using System.Security.Cryptography;
namespace Sandglass.Util.Security.Encrypt
{
/// <summary>
/// 安全哈希算法(Secure Hash Algorithm)
/// </summary>
public class HASH
{
/// <summary>
/// Description:[此算法没有解密]安全哈希算法(Secure Hash Algorithm)
/// 主要适用于数字签名标准(Digital Signature Standard DSS)
/// 里面定义的数字签名算法(Digital Signature Algorithm DSA)。
/// 对于长度小于2^64位的消息,SHA1会产生一个160位的消息摘要。
/// 当接收到消息的时候,这个消息摘要可以用来验证数据的完整性。
/// 在传输的过程中,数据很可能会发生变化,那么这时候就会产生不同的消息摘要。
/// </summary>
/// <param name=\"encryptString\">待加密的字符串</param>
/// <returns>加密成功返回加密后的字符串,失败返回源串</returns>
public static string SHA1_Encrypt(string encryptString)
{
try
{
var strRes = Encoding.Default.GetBytes(encryptString);
strRes = new SHA1CryptoServiceProvider().ComputeHash(strRes);
var enText = new StringBuilder();
foreach (var iByte in strRes)
{
enText.AppendFormat(\"{0:x2}\", iByte);
}
return enText.ToString();
}
catch
{
return encryptString;
}
}
/// <summary>
/// Description:[此算法没有解密]进行两次加密码
/// 安全哈希算法(Secure Hash Algorithm)
/// 主要适用于数字签名标准(Digital Signature Standard DSS)
/// 里面定义的数字签名算法(Digital Signature Algorithm DSA)。
/// 对于长度小于2^64位的消息,SHA1会产生一个160位的消息摘要。
/// 当接收到消息的时候,这个消息摘要可以用来验证数据的完整性。
/// 在传输的过程中,数据很可能会发生变化,那么这时候就会产生不同的消息摘要。
/// </summary>
/// <param name=\"encryptString\">待加密的字符串</param>
/// <returns>加密成功返回加密后的字符串,失败返回源串</returns>
public static string SHA1_Encrypt_Double(string encryptString)
{
return SHA1_Encrypt(SHA1_Encrypt(encryptString));
}
}
}
安全哈希算法
最新推荐文章于 2023-06-09 10:11:56 发布