在Windows窗体哈希与SHA-256的文本 [英] Hashing text with SHA-256 at Windows Forms
本文介绍了在Windows窗体哈希与SHA-256的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
字符串inputPass = textBox2.Text;
字节[] = inputBytes System.Text.Encoding.UTF8.GetBytes(inputPass);
字节[] = inputHashedBytes Sha256.ComputeHash(inputBytes);
字符串inputHash = Convert.ToBase64String(inputHashedBytes);
我收到一些奇怪的输出:
< BLOCKQUOTE>
Q9nXCEhAn7RkIOVgBbBeOd5LiH7FWFtDFJ22TMLSoH8 =
块引用>
通过输出散列看起来是这样的:
43d9d70828409fb46420e56005b05e38de4b887ec5585b43149db64cc2d2a07f
块引用>
解决方案//这是你在哪里得到实际的二进制哈希值
字节[] = inputHashedBytes Sha256.ComputeHash(inputBytes);
//但你要在一个字符串格式,类似的各种UNIX工具
字符串结果= BitConverter.ToString(inputHashedBytes)
//这将删除所有在每两个字符
.Replace( - ,的String.Empty)之间划线
//并使其小写
.ToLower();
String inputPass = textBox2.Text; byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(inputPass); byte[] inputHashedBytes = Sha256.ComputeHash(inputBytes); String inputHash = Convert.ToBase64String(inputHashedBytes);
I'm getting some strange output:
Q9nXCEhAn7RkIOVgBbBeOd5LiH7FWFtDFJ22TMLSoH8=
By output hash looks like this:
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();
这篇关于在Windows窗体哈希与SHA-256的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文