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();
Encoding.UTF8.GetString
解析字节码点UTF8。
该SHA256哈希值是一个任意256位数,不对应任何Unicode文本。
你可能想通过调用显示十六进制的二进制值, BitConverter.ToString()
您也可以拨打Convert.ToBase64String()