十六进制表示问题
如果我想要以下结果:
RIPEMD-160("The quick brown fox jumps over the lazy dog") =
37f332f68db77bd9d7edd4969571ad671cf9dd3b
我尝试了这个:
string hash11 = System.Text.Encoding.ASCII.GetString(RIPEMD.ComputeHash(Encoding.ASCII.GetBytes("The quick brown fox jumps over the lazy dog")));
但它没有给我以前的结果!
If I want the following result :
RIPEMD-160("The quick brown fox jumps over the lazy dog") =
37f332f68db77bd9d7edd4969571ad671cf9dd3b
I tried this :
string hash11 = System.Text.Encoding.ASCII.GetString(RIPEMD.ComputeHash(Encoding.ASCII.GetBytes("The quick brown fox jumps over the lazy dog")));
but it doesn't give me the previous result!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ComputeHash 函数为您提供一个字节数组,其中包含值(0x37、0xF3,...)。如果您使用 GetString,它将获取字节中的每个值并使用具有该值的字符,它不会将该值转换为字符串。
你可以这样转换它:
就像你在开头有最高字节。 。
开头的字节是最低的
The ComputeHash function gives you a byte array with the values in it (0x37, 0xF3, ...). If you use GetString it will take every value in the byte and use the character with that value, it will not convert the value into a string.
You could convert it like that:
Like that you have the highest byte at the beginning. With
you have the lowest byte at the beginning.
您想要获得的是字节数组的十六进制表示:每个字节应由其两个字符的十六进制值表示。
您可以查看此线程,了解如何执行此操作的几个不同示例。
What you want to get is the hex representation of the byte array: each byte should be represented by its two-character hex value.
You can check this thread for several different examples on how to do that.