加密和解密

Jai*_*ain 3 c# encryption sha1

我想使用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;
}
Run Code Online (Sandbox Code Playgroud)

它不起作用.它只返回System.Char [].我在这做错了什么

Rap*_*aus 5

因为这是ToString()从一系列字符返回的...

尝试

new string(new ASCIIEncoding().GetChars(bytehash));
Run Code Online (Sandbox Code Playgroud)

并选择莫里斯的答案,这是更聪明的;)