SHA1加密
public static string EncryptSHA1(string input, string salt)
{
// 将密码和salt值转换成字节形式并连接起来
byte[] bytes = Encoding.Unicode.GetBytes(input);
byte[] src = Convert.FromBase64String(salt);
byte[] dst = new byte[src.Length + bytes.Length];
Buffer.BlockCopy(src, 0, dst, 0, src.Length);
Buffer.BlockCopy(bytes, 0, dst, src.Length, bytes.Length);
// 选择算法,对连接后的值进行散列
HashAlgorithm algorithm = HashAlgorithm.Create("SHA1");
byte[] inArray = algorithm.ComputeHash(dst);
// 以字符串形式返回散列值
return Convert.ToBase64String(inArray);
}
使用方法:
public string Password { get; set; }
this.Password = EncryptionUtility.EncryptSHA1(this.Password, EncryptionUtility.GenerateSalt());