我想使用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[]。我在这里做错了什么
发布于 2014-07-04 08:54:01
因为这是ToString()从一系列字符中返回的.
试一试
new string(new ASCIIEncoding().GetChars(bytehash));选择莫里斯的答案,这个答案更聪明;)
发布于 2014-07-04 08:56:23
使用GetString而不是GetChars
var stringhash = new ASCIIEncoding().GetString(bytehash);然而,Spender给你写了一个关于你的问题的评论,链接到另一个问题,这将帮助你解决你的实际问题。(@Spender,谢谢)。
https://stackoverflow.com/questions/24570286
复制相似问题