c# - 在 Windows 窗体中使用 SHA-256 散列文本

标签 c# winforms utf-8 sha

String inputPass = textBox2.Text;
byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(inputPass);
byte[] inputHashedBytes = Sha256.ComputeHash(inputBytes);
String inputHash = Convert.ToBase64String(inputHashedBytes);

我得到了一些奇怪的输出:

Q9nXCEhAn7RkIOVgBbBeOd5LiH7FWFtDFJ22TMLSoH8=

通过输出哈希看起来像这样:

43d9d70828409fb46420e56005b05e38de4b887ec5585b43149db64cc2d2a07f

最佳答案

// This is where you get the actual binary hash
byte[] inputHashedBytes = Sha256.ComputeHash(inputBytes);

// But you want it in a string format, similar to a variety of Unix tools
string result = BitConverter.ToString(inputHashedBytes)
   // This will remove all the dashes in between each two characters
   .Replace("-", string.Empty)
   // And make it lowercase
   .ToLower();

关于c# - 在 Windows 窗体中使用 SHA-256 散列文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11477083/

相关文章:

c# - 如何在 DataGridView 中更改单元格值时进行监视?

VB.NET 限制选项卡排序?

php - 如何使用 utf-8 编码 mySQL 连接

python-2.7 - 获取适当长度的表情符号

android httpclient 和 utf-8

c# - DateTime XAML 绑定(bind)字符串格式以显示 DateTime.MinValue 的 "null"

c# - 如何在游戏中拥有局部位置和全局位置

c# - 无懈可击的 XMLException

c# - 获取特定类型的所有控件

c# - TreeView拖放帮助-_Invalid FORMATETC structure异常