[A web3 concept every day] Must-know cryptography
Encryption algorithms are the most commonly heard concepts in public chains, wallets and other fields. But how to ensure the security of the wallet and how to ensure the link of the block? This all requires the help of cryptography. Cryptographic technology is the underlying technology for the security of blockchain systems. Hash functions and public-private key pairs commonly used in web3 are representatives of them.
Hash Function: Also called hash function, or hash for short, it can realize input of any length and convert it into a fixed-length output: h=H(m), which means that whatever you input will be hashed Algorithm, what is finally obtained is a string of fixed-length characters, one input corresponds to one output, and its security is based on its collision resistance (Collision-Resistant), that is, it is difficult to find two inputs with the same output.
In the blockchain, hash functions are used in two places, one is the Merkle tree root hash, and the other is the block pointer connecting the blocks. The Merkle tree root hash is to hash all transactions, then form a new value and then hash it. Finally, only one hash value is found, which is the Merkle tree root hash. Because it is impossible to find two inputs with the same output, this means that as long as the content of the transaction changes, the Merkle tree root hash will also change, so as long as the root hash does not change, the transaction is correct. In the same way, find a hash for the entire block data, and put the entire hash value into the next block header. As long as the hash value remains unchanged, it means that all previous blocks have not been tampered with. , are all correct.
Public-private key pair: It is the famous public key cryptography algorithm.
Public key cryptography uses a pair of related keys for encryption and decryption: a public "public key" and a secret "private key." The "public key" can be disclosed to anyone and used to encrypt data. The "private key" must be kept secret and known only to the owner. It is used to decrypt data encrypted by the corresponding public key.
Public key cryptography algorithms are based on the complexity of certain mathematical problems. For example, the security of the RSA algorithm (a popular example of asymmetric encryption) is based on the difficulty of factoring large numbers. In other words, you can think of this process as a "black box" for encryption and decryption.