Each byte is represented by an 8-bit binary number, and the 256 possible characters represented by this 8-bit binary number are clearly defined in ASCII code.
The problem is that only some of these 256 characters are what we usually understand:
Therefore, when the address is converted into a string display, the value beyond the above range can only be displayed in a form that we can't understand, that is, garbled code.
Since the garbled code is displayed because the ASCII code is beyond the required range, it is enough to encode the binary value in a certain encoding way to make it fall into the range that can be displayed normally.
The concrete realization of the coding method has been done, and it is no longer necessary to make the wheel repeatedly, so it can be taken away and used directly.
The implementation includes Base coding series: Base64, Base32, Base 16.
Base32 coding is adopted here:
It is characterized in that:
Then let's practice:
The result is a 56-byte array, which exceeds the length of 32 bytes we need. Why?
Take a closer look at the principle of Base32 coding:
In this encoding process, the length of byte array will undoubtedly be enlarged. After calculation, a 32-byte byte array will be enlarged to a 56-byte byte array. And if the final result is required to be a 32-byte byte array, you are required to enter a byte array with a value of 20 bytes!
The way to get a 20-byte byte array is simple:
We chose the second method, because the results generated by hashing are difficult to copy and cannot be guaranteed if intercepted.
Verification result:
In this way, we get the string address that needs to be displayed normally.