c# - 我如何在 C# 中对字符串进行 SHA512?

标签 c# hash

我正在尝试编写一个函数来获取字符串并像这样对其进行 sha512 处理?

public string SHA512(string input)
{
     string hash;

     ~magic~

     return hash;
}

魔法应该是什么?

最佳答案

您的代码是正确的,但您应该处理 SHA512Managed 实例:

using (SHA512 shaM = new SHA512Managed())
{
   hash = shaM.ComputeHash(data);
}

512 位是 64 字节。

要将字符串转换为字节数组,您需要指定一种编码。如果你想创建一个哈希码,UTF8 是可以的:

var data = Encoding.UTF8.GetBytes("text");    
using (...

关于c# - 我如何在 C# 中对字符串进行 SHA512?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11367727/

相关文章:

algorithm - 为一组整数生成 id

algorithm - 将域中的一组整数散列到一组桶中

php - 在 windows、linux 和 Mac 上为同一图像创建不同的哈希值

hash - 你如何在 openLDAP 中打开密码散列 (SSHA)

c# - Process.Start 中的 ID 有时匹配,有时不匹配

c# - 通过 Interop 为 Microsoft Access 创建宏

c# - 使用 linq 查询输出列表/其他数据结构

c# - 如何从嵌入式资源加载 HTML/JavaScript 到 winform web 浏览器

c# - 如何覆盖嵌入在 Telerik 程序集中的样式表?

c++ - 在 C++ 中使用数组创建哈希表表示