加密:
public string StrEncrypt(string pwd)
{
var sha1 = new SHA1Managed();
byte[] sha1Res = sha1.ComputeHash(Encoding.ASCII.GetBytes(pwd));
byte[] joinByte = new byte[sha1Res.Length];
sha1Res.CopyTo(joinByte, 0);
string base64Str = Convert.ToBase64String(joinByte);
byte[] aa = sha1.ComputeHash(Encoding.ASCII.GetBytes(pwd));
string old = "";
foreach (var item in aa)
{
old += item.ToString("X2");
}
Console.WriteLine(old);
return "{SHA}" + base64Str;
}
使用:
string t1 = StrEncrypt("secret");
Console.WriteLine(t1);
网友评论