Current location - Quotes Website - Personality signature - The difference between public key and private key and its application.
The difference between public key and private key and its application.
In real life, I want to transfer 1 bitcoin to Yiyi. I need to enter my bitcoin wallet address, Yiyi's wallet address, the number of transferred bitcoins and the handling fee in the bitcoin trading platform, bitcoin wallet or bitcoin client. Then, we waited for about ten minutes. After the miners processed the transaction information, 1 bitcoin was successfully transferred to Yiyi.

This process seems very simple and convenient, and it is no different from our current bank card transfer, but do you know how this process is realized in the Bitcoin system? What principles does it hide? Or, how can it ensure that the transaction can be carried out in a safe environment?

Let's talk about it today

For the sender and the receiver, namely Yiyi and I (I am the sender and Yiyi is the receiver), we need to publish two things: the wallet address and the private key.

Say the wallet address first. Bitcoin wallet address is actually equivalent to bank card, Alipay account and WeChat wallet account. It is a "voucher" for bitcoin payment and transfer, and records the transfer information between platforms, wallets and wallets.

We need a password to use bank card, Alipay and WeChat to transfer money, in order to pay successfully. Then in bitcoin transfer, there is also such a "password" called "private key". When you master the private key, you have the power of life and death on its corresponding bitcoin address.

Private key belongs to the concept of asymmetric encryption algorithm, and there is another concept corresponding to it, called public key.

Public key and private key can be understood literally: public key can be made public; However, the private key is private, owned by yourself and needs to be kept absolutely confidential.

The public key is calculated according to the private key, and the Bitcoin system uses elliptic curve encryption algorithm to calculate the public key according to the private key. This makes the public key and private key form a unique correspondence: when you encrypt information with one key, only the other key can decrypt it. Therefore, based on this unique correspondence, they can be used to verify the identity of the sender of information, or they can be kept absolutely confidential.

Let's illustrate how public and private keys work in asymmetric encryption algorithms.

We know that public keys can be made public, so everyone knows our public keys. In the process of transferring funds, I must not only ensure that Bitcoin is transferred to Yiyi, but also cannot be transferred to others. I must also let Yiyi know that I transferred these bitcoins to her, not deer or Jiu Ge.

Bitcoin system can meet my above demands: Bitcoin system will shorten my transaction information into a fixed-length string, that is, a summary, and then attach my private key to this summary to form a digital signature. Because the digital signature contains my private key information, it can prove my identity.

Upon completion, the complete transaction information and digital signature will be broadcast to the miners together. Miners will use my public key to verify whether my public key and my digital signature match. If the verification is successful, there is no problem. Then, it can be said that the transaction was indeed sent by me and the information has not been changed.

Next, the miners need to verify whether the bitcoin spent in this transaction is "unused". If the verification is successful, put it in "unconfirmed transaction" and wait for packaging; If the verification fails, the transaction will be marked as "invalid transaction" and will not be packaged.

In fact, the simple understanding of public key and private key is: since they are encrypted, they certainly don't want others to know my message, so only I can decrypt it, so it can be concluded that the public key is responsible for encryption and the private key is responsible for decryption; By the same token, since it is a signature, I certainly don't want anyone to impersonate me. Only I can publish this digital signature, so it can be concluded that the private key is responsible for signing and the public key is responsible for verification.

Here, let's briefly summarize the above contents. Above we mainly talk about the following words: private key, public key, wallet address and digital signature. Let's look at the relationship between them:

(1) The private key is randomly generated by the system, the public key is calculated by the private key, and the wallet address is calculated by the public key, that is, the process of private key-public key-wallet address;

(2) Digital signature is calculated from transaction information+private key information. Because the digital signature contains private key information, it can prove its identity.

Both private key and public key belong to the field of cryptography and belong to the "elliptic encryption algorithm" in the "asymmetric encryption" algorithm. The reason why this algorithm is adopted is to ensure the security of the transaction. Their functions are as follows:

(1) public key encryption, private key decryption: the public key is made public on the whole network. I use Yiyi's public key to encrypt information, and Yiyi can decrypt it with her own private key;

(2) Private key signature, public key verification: I send a message to Yi, I add my private key information to form a digital signature, and Yi uses my public key to verify. The successful verification proved that it was indeed my message.

However, in bitcoin transactions, encryption, decryption and verification are all given to miners.

As for the wallet APP that we often use now, it is just a tool to manage blockchain data such as private keys and wallet addresses. Wallets are divided into cold wallets and hot wallets. The cold wallet is offline and never connected to the Internet. Generally in the form of some entities, such as small notebooks. Hot wallets are networked, and the wallet APP we use belongs to hot wallets.