c# - 加解密

标签 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;
}

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

最佳答案

因为这就是 ToString() 从字符数组返回的内容...

尝试

new string(new ASCIIEncoding().GetChars(bytehash));

然后选择 Maurice 的答案,这是更聪明的 ;)

关于c# - 加解密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24570286/

相关文章:

ssl - 如果没有为 TLSv1.0 启用密码,协商还能进行吗?

java - BadPaddingException 仅包含 "o"、 "b"、 "c"等字母

php - 不同 php 版本上的不同 sha1 校验和?

blob - 如何使用CryptoJS获取BLOB的正确SHA1哈希?

java - Sha1WithRSA 和 Sha1WithRSAEncryption 之间的区别?

c# - 回到程序的开始

c# - WPF 数据绑定(bind)验证被忽略

c# - 尝试使用 Python 从工作 C# 代码生成 RSA 签名

c# - MahApps MetroProgressBar 无法在 ControlTemplate 内工作

c# - 将 String 与省略空行进行比较?