gpt4 book ai didi

c# - 我应该如何在 C# 中散列这些数据?

转载 作者:太空宇宙 更新时间:2023-11-03 22:45:04 26 4
gpt4 key购买 nike

我有一个字符串数据字段,它是 12 个字符,字母数字(字母和数字)。出于安全原因,我需要对该字段执行单向哈希。我应该使用什么算法来避免冲突(不同的值散列为相同的值)以实现准确的报告?这会成功吗?

Edit: Here is the code based on suggestions in comments so far:

public static string GetHashedValue(string Input)
{
byte[] bytes = System.Text.Encoding.Unicode.GetBytes(Input);
bytes = new System.Security.Cryptography.SHA512Managed().ComputeHash(bytes);
String output = Convert.ToBase64String(bytes);
return output;
}

最佳答案

我建议你应该得到一个base64字符串来防止数据丢失,这样你就可以避免高碰撞机会。即:

public static string GetHashedValue(string Input)
{
byte[] bytes = System.Text.Encoding.Unicode.GetBytes(Input);
bytes = new System.Security.Cryptography.SHA512Managed().ComputeHash(bytes);
string output = Convert.ToBase64String(bytes);
return output;
}

编辑:哈希是一种方式,非常适合存储密码。如果您想使用 key 返回原始值,请使用对称算法。

关于c# - 我应该如何在 C# 中散列这些数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50375987/

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