[英]Encryption & Decryption
I want to have a Encryption using SHA1. 我想使用SHA1进行加密。 My Code is
我的代码是
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;
}
It's not working. 它不起作用。 It only return System.Char[].
它只返回System.Char []。 What am I doing wrong in this
我在这做错了什么
Because that's what ToString()
returns from an array of chars... 因为这就是
ToString()
从一个字符数组返回的内容......
try 尝试
new string(new ASCIIEncoding().GetChars(bytehash));
and choose Maurice's answer, which is smarter ;) 并选择莫里斯的答案,这是更聪明的;)
Use GetString
instead of GetChars
使用
GetString
而不是GetChars
var stringhash = new ASCIIEncoding().GetString(bytehash);
However Spender wrote you a comment on your question with a link to another question that will help you resolve your actual problem. 然而,Spender为您的问题写了一条评论,其中包含另一个问题的链接,可以帮助您解决实际问题。 (@Spender thanks for this).
(@Spender感谢此事)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.