Introduction to Common Data Algorithms of Blockchain

When learning about blockchain in depth, it is inevitable to need to understand cryptography. Cryptography has been around for a long time, with a history of thousands of years, and has been widely used in military, diplomatic, intelligence and other fields. In the field of blockchain, cryptographic algorithms, such as hash algorithm and elliptic curve algorithm, are also widely used. These data encryption algorithms are an important part of the technology. The following is a detailed introduction to the three most commonly used data algorithms in the blockchain.
1. Hash algorithm
Hash algorithm is also called hash algorithm or digest algorithm, which maps a binary value of any length to a shorter fixed-length binary value. This small binary value is called a hash value. Its principle is actually very simple, which is to convert a piece of transaction information into a fixed-length string, but as long as the original data is slightly changed, the hash value obtained is completely different. Because of this feature, the hash algorithm is usually used to complete the data. sex check and password verification. Therefore, the hash algorithm is a one-way encryption algorithm, which has three important properties, namely anti-collision, irreversible pre-image, and problem-friendly. This algorithm is used in the blockchain to generate block hashes, transaction hashes, and proof of work.

Common hash algorithms are: MD2, MD4, MD5, HAVAL, SHA-1, SHA256, SHA512, RipeMD, WHIRLPOOL, SHA3, HMAC
insert image description here

2. Asymmetric encryption algorithm
If there is asymmetric encryption, there must be a symmetric encryption algorithm. By the way, here is a brief introduction to the symmetric encryption algorithm. Symmetric encryption algorithm means that the same secret key is used for encryption and decryption. Unlike symmetric encryption algorithms, asymmetric encryption algorithms require two keys: a public key (publickey) and a private key (privatekey). The public key and the private key are a pair. The private key can deduce the public key but the public key cannot deduce the private key. If the data is encrypted with the public key, only the corresponding private key can be used to decrypt it; if the data is encrypted with the private key If encrypted, only the corresponding public key can be used to decrypt it. Simply put, "encrypt with the public key, decrypt with the private key; encrypt with the private key, decrypt with the public key".

In the blockchain, digital signatures are based on the above-mentioned asymmetric encryption technology. The difference is that digital signatures use a private key to generate a signature, and the receiver uses a public key for verification. For example, after using the private key to decrypt the plaintext above, use the private key to sign the reply, and after receiving the reply, use the public key to decrypt the content and the data to prove that the signature is correct.

A common signature algorithm in blockchain technology is elliptic curve cryptography. Its algorithm is expressed by adding or multiplying points on the elliptic curve. The private key in the blockchain is a random number, and the public key is generated through the elliptic curve signature algorithm. But it is almost impossible to reversely calculate the private key from the public key. The elliptic curve signature algorithm also has the characteristics of high security and small storage space.

In the use of daily business codes, if data encryption is required, the public key is generally used for encryption and the private key for decryption. After all, the public key can be made public, but only you know the private key, and you also hope that only you can decrypt it; if a signature is required, the private key encrypts and the public key decrypts. For example, your signature is only true if you sign it yourself, and all other people's signatures are fake.

Common asymmetric encryption algorithms include: RSA, ECC (elliptic curve encryption algorithm), Diffie-Hellman, El Gamal, DSA (for digital signatures).
insert image description here

3. Base58 encoding algorithm
Like the usual base64 encoding, the function of base58 encoding is also to visualize non-visual characters (ASCII). But the difference is that base58 encoding removes several seemingly ambiguous characters, such as 0 (zero), O (uppercase letter O), I (uppercase letter i) and l (lowercase letter L), and several Characters that affect double-click selection, such as /, +. The resulting character set is exactly 58 characters (including 9 numbers, 24 uppercase letters, and 25 lowercase letters). And because 58 is not an integral power of 2, it does not use a method similar to base64 encoding that directly intercepts 3 characters and converts 4 characters (3 8=4 6 , 2 to the 6th power is exactly 64) for conversion, but uses The hexadecimal conversion method we often use in mathematics - the method of rolling and dividing (essentially, base64 encoding is hexadecimal, base58 is hexadecimal 58).
Base58 is the encoding method used by many public chain addresses, such as Bitcoin, which is mainly used to generate wallet addresses. This encoding format not only achieves data compression, maintains legibility, but also has error diagnosis functions.

Guess you like

Origin blog.csdn.net/qq_41547320/article/details/125766646