Do the SHA1 of a string always return ASCII characters?

谁都会走 提交于 2021-02-18 10:31:24

问题


The input string can be a unicode string.Do the output string after calculating SHA1 will always return ASCII characters?


回答1:


It depends but strictly speaking, no. The output of the SHA-1 hash is 160 bits, or 20 bytes, but the bytes are not guaranteed to be in the ASCII range.

However, some hash functions output the hex equivalent (i.e. 40 characters) of the 20 bytes, so if the first three bytes of the actual hash are 0x7e, 0x03, and 0xb2, the output would begin with "7e03b2", in which case the output is ASCII.




回答2:


sha1 returns a binary string. Some sha1 functions may, as a convenience, also encode that binary string into hexadecimal or base64 - if so, the result will be ASCII characters. But sha1 itself does not return ASCII.




回答3:


SHA1 returns 20 bytes. SHA1 does not deal with encodings, text, ASCII, etc.

One common way to represent binary data is by encoding it in hexadecimal - in this case, the output is always [a-f][0-9]



来源:https://stackoverflow.com/questions/6529507/do-the-sha1-of-a-string-always-return-ascii-characters

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