gpt4 book ai didi

c# - 加解密

转载 作者:行者123 更新时间:2023-11-30 13:56:48 25 4
gpt4 key购买 nike

我想使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com