我想使用 SHA1 进行加密。我的代码是
public static string EncryptPassword(string password)
{
try
{
SHA1 sha1 = new SHA1Managed();
var bytehash = sha1.ComputeHash(new MemoryStream(new ASCIIEncoding().GetBytes(password)));
var stringhash = new ASCIIEncoding().GetChars(bytehash).ToString();
return stringhash;
}
catch (Exception ex)
{
// Some Exception....
}
return null;
}
它不起作用。它只返回 System.Char[]。我做错了什么
最佳答案
因为这就是 ToString()
从字符数组返回的内容...
尝试
new string(new ASCIIEncoding().GetChars(bytehash));
然后选择 Maurice 的答案,这是更聪明的 ;)
关于c# - 加解密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24570286/