1)使用 SHA1 生成散列
通过如下的示例代码,来演示如何通过SHA1生成散列:
byte [] bytePassword = null;
string tmpPassword = txtPassword.Text.Trim();
// 创建新的加密服务提供程序对象
SHA1 sha1 = SHA1.Create();
// 将原始字符串转换成字节数组,然后计算散列,并返回一个字节数组
bytePassword = sha1.ComputeHash(Encoding.Unicode.GetBytes(tmpPassword));
// Releases all resources used by the System.Security.Cryptography.HashAlgorithm.
sha1.Clear();
// 返回散列值的 Base64 编码字符串
txtResults.Text = Convert.ToBase64String(bytePassword);