Hashing text with SHA-256 at Windows Forms

混江龙づ霸主 提交于 2019-12-06 11:14:52
// 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();

Encoding.UTF8.GetString parses bytes as UTF8 codepoints.

The SHA256 hash is an arbitrary 256-bit number and does not correspond to any Unicode text.

You probably want to show the binary value in hexadecimal, by calling BitConverter.ToString().
You can also call Convert.ToBase64String().

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!