Base58 is a group of binary-to-text encoding schemes used to represent large integers as alphanumeric text. It is similar to Base64 but has been modified to avoid both non-alphanumeric characters and letters which might look ambiguous when printed. It is therefore designed for human users who manually enter the data, copying from some visual source, but also allows easy copy and paste because a double-click will usually select the whole string.
How it works?
The Base58 encoding format is designed for use in Bitcoin and is used in many other cryptocurrencies. It offers a balance between compact performance, readability, definition and error prevention. Base58 is a subset of Base64 that uses lowercase and uppercase letters and numbers, but without some characters that are often mistaken for each other and can be identical in some fonts. In particular, Base58 is Base64 without the number 0 (zero), O (capital letter O), l (small L), I (large i), and the characters "\+" and "/". Or, simply put, it is a set of uppercase and uppercase letters and numbers without the four (0, O, L, I) mentioned above.In contrast to Base64, the digits of the encoding do not line up well with byte boundaries of the original data. For this reason, the method is well-suited to encode large integers, but not designed to encode longer portions of binary data. The actual order of letters in the alphabet depends on the application, which is the reason why the term “Base58” alone is not enough to fully describe the format. A variant, Base56, excludes 1 (one) and o (lowercase o) compared to Base 58.
Base58Check is a Base58 encoding format that unambiguously encodes the type of data in the first few characters and includes an error detection code in the last few characters.
Base58 Encode and Decode
With Base58, private key can be converted to a public key, but a public key cannot be converted to a private key. The bitcoin address is not really a public key, but its hash. So, the bitcoin address corresponding to the given above public key will be:
Bitcoin address is not presented in hexadecimal form as secret and public keys. This is because for him, Bitcoin uses a "compressed" format, known as base58check. Bitcoin Base58 suggests that it uses 58 different letters and numbers (zero, O, l and I are omitted, as they are too easily confused with each other). Base58 is a number with a base 58-similar to the usual for us binary (base 2), decimal (base 10) or hexadecimal (base 16) representation. For example, the decimal number 31337 in binary form would be ‘111101001101001’, in hexadecimal it would be ‘7A69’, and at base 58 it would just be ‘AKJ’. Well, the suffix check in the description of the format means that before the translation of a number in base58 it still adds a four-byte "check sum". All bitcoin libraries (which we will talk about later) make a transfer to base58check automatically, so you do not have to program it specifically.
To add additional protection against typos or transcription errors, Base58Check is a Base58 with built — in error checking code. Four bytes of checksum are added to the end of the encoded data. The checksum is obtained by hashing the encoded data and can therefore be used to detect and prevent transcription and typo errors. The software will calculate the checksum of the data when decoding and compare it with the checksum of the code. The mismatch will indicate an error and the Base58Check data will be invalid. For example, such a check prevents the possibility of sending funds to a non-existent Bitcoin address and thus losing funds.
To convert data (numeric) to Base58Check format, you must first add a prefix to The data, called a "version byte", which is used to determine the type of data to be encoded. For example, in the case of a Bitcoin address, the prefix is 0 (0x00 in the hex system), while the prefix for the private key is 128 (0x80 in the hex system).
Next, we compute a checksum of the "double-SHA", in the sense that the used hash algorithm is SHA256 twice on the previous result (prefix and data).
checksum = SHA256(SHA256(prefix+data))
From the resulting 32-byte hash (hash of hash), we take only the first four bytes. These four bytes serve as the error-checking code, or checksum. This checksum is then added to the end of the line. The result consists of three elements: prefix, data, and checksum. This result is encoded using the Base58 alphabet described earlier.
|Application||Alphabet||Excluded Base64 characters|
|Bitcoin addresses, IPFS hashes||
|Short URLs for Flickr||
- Andreas M. Antonopoulos. "Mastering Bitcoin". section "Base58 and Base58Check Encoding". (O’Reilly, 2015).
- Technical background of version 1 Bitcoin addresses
- IPFS API Implementation Doc
- Photo Source URLs
- Flickr API