为广大币圈朋友提供币圈基础入门专业知识!
当前位置首页 > 比特币基础> 正文

区块链智能合约中的公钥和私钥的区别,区块链智能合约中的公钥和私钥是什么

发布时间:2023-12-09-13:25:00 来源:网络 比特币基础 区块   合约   智能

区块链智能合约中的公钥和私钥的区别,区块链智能合约中的公钥和私钥是什么

区块链智能合约中的公钥和私钥是什么?公钥和私钥的区别是什么?今天我们就来聊聊区块链智能合约中的公钥和私钥,以及它们之间的区别。

1. 公钥:

公钥是在公开的区块链网络中使用的一个共享的密钥,它可以用于加密消息,确保消息的安全性和保密性。公钥是由区块链智能合约的发行者生成的,并且可以在区块链网络中被任何人查看和使用。

2. 私钥:

私钥是与公钥相对应的一个私有密钥,它可以用于解密消息,以确保消息的安全性和保密性。私钥是由智能合约的发行者生成的,它只能在发行者的计算机上查看和使用,不能在公开的区块链网络中查看和使用。

3. 区别:

公钥和私钥之间的最大区别在于它们的可见性。公钥是可以在公开的区块链网络中被任何人查看和使用的,而私钥则只能在发行者的计算机上查看和使用,不能在公开的区块链网络中查看和使用。另外,公钥是用于加密消息,而私钥则用于解密消息。

总的来说,区块链智能合约中的公钥和私钥是一对非常重要的密钥,它们之间的区别在于它们的可见性和用途,它们可以帮助我们确保消息的安全性和保密性。


请查看相关英文文档

『一』What is the relationship between blockchain private key, public key and address?

The relationship between blockchain private key, public key and address is private The key generates a public key, and the public key is converted into an address. So the private key is the most important. The three are irreversible. The address cannot generate a public key, and the public key cannot be converted into a private key.

The blockchain address is again, which usually consists of a string of letters and numbers of 26 to 35 characters. The blockchain address is mainly derived from the public key, block The chain address is equivalent to the bank card number we usually use. It can be disclosed to anyone with no security restrictions. Its main function is to receive and send digital assets on the blockchain.

Blockchain technology is now in its early stages of development, but because of its decentralization, security, non-tampering and other characteristics, it may have killer-level applications in life and work in the future and has attracted much attention from various countries. Pay attention to. This article is for reference only, please leave a message for discussion.

『二』 Lesson 4 Summary of cryptography learning in blockchain

This is the fourth lesson of deep learning in Ulord. Dr. Yang will give everyone a lecture on cryptography in blockchain. Regarding cryptography issues, this course helped me understand a question about public keys and private keys that has been bothering me. What is the relationship between them? I got the answer in this study, and now I will share with you what I learned.

The public key and private key in the blockchain are two basic concepts in asymmetric encryption.

Public key and private key are a key pair obtained through an algorithm. The public key is the public part of the key pair, and the private key is the non-public part. Public keys are usually used to encrypt conversations, that is, messages or information, and can also be used to verify digital signatures signed with private keys.

The private key can be used to sign and the corresponding public key can be used for verification. The key pair obtained through this public key system can be guaranteed to be unique worldwide. When using this key pair, if you use one of the keys to encrypt data, you must use its corresponding other key to decrypt it.

For example, data encrypted with a public key must be decrypted with a private key. If encrypted with a private key, the corresponding public key must be used to decrypt it, otherwise the decryption cannot be successful. In addition, in the Bitcoin blockchain, the public key is calculated through the private key, and the address is calculated through the public key, and this process is irreversible.

『三』What does the private key in the blockchain mean?

The term private key and public key can be said to be the simplest of all exam questions.
The public key is called the public key, and the key that only you know is called the private key.
Public Key and Private Key are a key pair (i.e. a public key and a private key) obtained through an algorithm. The public key is the public part of the key pair., the private key is the non-public part.
Clear in one sentence~

『四』What are the basic knowledge of blockchain

1. FISCO BCOS uses accounts to identify and distinguish each independent user. In a blockchain system that uses a public-private key system, each account corresponds to a pair of public and private keys. Among them, the address string obtained by calculating the public key through a secure one-way algorithm such as hashing is used as the account name of the account, that is, the account address. The private key known only to the user corresponds to the password in the traditional authentication model. Such accounts with private keys are also often called external accounts or accounts.

2. The smart contract deployed on the chain in FISCO BCOS also corresponds to an account in the underlying storage. We call this type of account a contract account. The difference between it and an external account is that the address of the contract account is when it is deployed. Determined, calculated based on the deployer's account address and the information in his account, and the contract account does not have a private key.

3. The SDK needs to hold the external account private key and use the external account private key to sign the transaction. In the blockchain system, every call to the contract writing interface is a transaction, and each transaction needs to be signed with the account's private key.

4. Permission control requires the address of an external account. The FISCO BCOS permission control model determines whether there is permission to write data based on the external account address of the transaction sender.

5. The contract account address uniquely identifies the contract on the blockchain. After each contract is deployed, the underlying node will generate a contract address for it. When calling the contract interface, the contract address needs to be provided.

『五』 Basic concepts of public key, private key, hash, and encryption algorithm

In life, we need to sign documents, and the handwriting of the signature is different for everyone, ensuring uniqueness , of course, there will be imitation, so for important documents, we will add a fingerprint. The fingerprint is unique, ensuring that the document is signed by us personally.

So in the blockchain world, the corresponding one is digital signature. Digital signature involves basic concepts such as public key, private key, hash and encryption algorithm.

First of all, encryption algorithms are divided into three categories: symmetric encryption algorithms, asymmetric encryption algorithms, and hash function encryption algorithms.

The so-called asymmetric encryption algorithm means that the public and private keys used for encryption and decryption are different. The asymmetric encryption algorithm relies on the difficulty of solving a mathematical problem and the simplicity of verifying a mathematical problem.

Asymmetric encryption system, the encryption is called the public key, the decryption is called the private key, public key encryption, private key decryption, private key signature, and public key verification.

There are two types of Bitcoin encryption algorithms: asymmetric encryption algorithms (elliptic curve encryption algorithms) and hash algorithms (SHA256, RIMPED160 algorithms)

Give an example to illustrate thisEncryption process: A sends a file to B. How does B know that the file he receives is the original file sent by A?

A can do this, first perform summary processing on the file (also called Hash, common hash algorithms include MD5, SHA, etc.) to obtain a string of summary information, and then use its own private key to convert the summary information Encrypt the same file and send it to B. After B receives the encrypted string and file, B uses A's public key to decrypt the encrypted string and obtains the summary information of the original file. At the same time, it performs summary processing on the received file, and then the two Compare the summary information. If the summary information you calculated is consistent with the summary information received, it means that the file is the original file sent by A and has not been tampered with. Otherwise, it has been modified.

Digital signatures have two functions:
First, it can confirm that the message is indeed signed and sent by the sender;
Second, digital signatures can confirm the integrity of the message.

The private key is used to create a digital signature, and the public key is used to allow others to verify the private key.
The digital signature serves as a medium to prove that you own the password and does not require You show the password.

The following is a definition of the concept:

Hash:
A digital fingerprint of binary input data.
It is a function through which any number or string input can be converted into a fixed-length output. It is a one-way output, that is, it is very difficult to deduce the input value in reverse.
Take an example of a simple hash function. For example, the square root of the number 17202 is 131.15639519291463. Through the output of a simple hash function, it gives the next few decimal places of the calculation result, such as the last few decimal places: 9291463 , through the result 9291463, it is almost impossible for us to deduce which input value it is the output of.
Modern cryptographic hashes, such as SHA-256, are much more complex than the above example and are therefore more secure. Hash is used to refer to the output value of such a function.

Private key:
A string of characters, such as +, used to unlock the corresponding (wallet) address.

Public key (Public keycryptography):
The encryption system is an encryption method. Each private key has a corresponding public key. We cannot deduce the private key from the public key. keys, and data encrypted with one of the keys can be decrypted by the other corresponding key. This system allows you to first publish a public key to allThen everyone can send encrypted information to you without exchanging keys in advance.

Digital signature:
Digital signature A digital signature is something that can be attached to a message to prove that the sender of the message is a public key The corresponding owner of a private key can also ensure the confidentiality of the private key. When someone checks the signature, they will use the public key to decrypt the encrypted hash value (Translator's Note: This hash value is obtained by hashing the data) and check whether the result matches the message. The hashes match. If the information has been altered, or the private key is wrong, the hashes will not match. In the world outside the Bitcoin network, signatures are often used to verify the identity of the sender of a message - someone publishes their own public key and then sends a message that can be verified by the public key and has been encrypted with the private key.

Encryption algorithm:
is a function that uses an encryption key to convert a message into an unreadable, seemingly random string. This process is irreversible , unless it is operated by someone who knows the private key. Encryption allows private data to be transmitted over the public Internet without running a serious risk of a third party knowing what is being transmitted.

Rough encryption process of hash algorithm
1. Supplement and segment the original text (generally divided into multiple 512-bit texts, and further divided into 16 32-bit integers ).
2. Initialize the hash value (generally divided into multiple 32-bit integers, for example, SHA256 is a 256-bit hash value divided into eight 32-bit integers).
3. Calculate the hash value (depending on different algorithms for different rounds of calculations, each 512-bit text must go through these rounds of calculations).

Each data block in the blockchain contains information about a network transaction, and asymmetric encryption technology is used to generate associated data blocks. The role of non-cryptographic encryption technology is to verify the validity of information and generate the next block. Information on network transactions on the blockchain is open and transparent, but the user’s identity information is highly encrypted and can only be identified with the user’s authorization. Only the blockchain can obtain this identity information, thereby ensuring the security of data and the privacy of personal information.

The public key and the private key exist in pairs in the asymmetric encryption mechanism. The public key and the private key can verify each other. So in the world of Bitcoin, we can understand the address as The public key can be understood as the process of signing and entering the password as the signature of the private key.
Each miner can verify whether the public key and private key match when receiving a transfer transaction.If they match, the transaction is legal. In this way, everyone only needs to keep their own private key and know their own Bitcoin address and the other party’s Bitcoin address to safely transfer Bitcoin. When transferring money, there is no need for a centralized institution to verify whether the Bitcoin sent by the other party is genuine.

『Lu』 In a blockchain-based digital currency like Honesty Coin, what exactly is the private key, public key, and address?

When many newbies first enter the market, I am confused by the relationship between private keys, public keys, addresses, etc. Some even lost their private keys, and there was a lot of money in the address, but they just couldn't get it out. Today Xiaobai will explain to you the relationship between private keys, public keys, and addresses.

The relationship between the private key, public key and address is:

The private key is converted (generated) into a public key, and then converted into an address. If there is Bitcoin or integrity coins on an address, you can Spend the integrity coins above using the private key converted to this address. The generation of public key and address both depends on the private key, so the private key is the most important.

The same is true for mobile wallets, but because the file management method of mobile phones is not as convenient as that of computers. Therefore, generally mobile wallets will provide a function called or similar to "Export Private Key". Through this function, the private key can be exported in various forms.

For example, the Bitcoin mobile wallet can be exported as a QR code, which can be printed or scanned onto paper. When changing your mobile phone, install your Bitcoin wallet and scan this QR code to migrate your Bitcoins. The Bitcoin mobile wallet and the Integrity Coin mobile wallet can be exported as a clear text string and printed on paper - this is a paper wallet.

The paper wallet allows users to go to any terminal with a Bitcoin or Integrity Coin wallet to spend your Bitcoin or Integrity Coin.

As the wallet is lost or damaged, the private key will be lost, thereby completely losing the right to transfer the digital currency. To prevent such a tragedy, remember to always back up the data in your wallet. In addition to the address, all private keys are also saved during the backup.

Summary

The private key must be protected to prevent loss and forgetting. The method will be cleared when clearing information on the mobile phone. It is best to copy it by hand, but do not disclose it.

You must prevent your wallet from being lost or damaged, resulting in the loss of the private key and the loss of the right to transfer digital currency. Otherwise, no matter how many coins you have, you can't withdraw them, it is still useless.

『撒』 [Cat Talk] There are two keys to open a Bitcoin wallet: private key and public key

If you don’t understand the blockchain, you don’t know the public key and private key. The most basic concept is that for newcomers to the cryptocurrency industry, owning a wallet is like poking a crocodile in the head with your finger. The risk is extremely high. This article is dedicated to new friends in the currency circle to help you sort out the basic common sense of Bitcoin wallets.

Blockchain Observation Network mentioned in the article "What is Blockchain" that in the blockchain world, everyone has two unique virtual keys: public key and private key.

"Public Key",It can be simply understood as a bank card, which can be sent to the counterparty to see the transaction. The bank card number is equivalent to the "address" used in Bitcoin transfers.

To put it more professionally, the public key is a 65-byte string. How long is it? 130 letters and numbers stacked together. If the public key is too long, firstly, it will be too troublesome to make transactions. Secondly, why do you have to expose the true content of the public key? This is like taking out your bank card and showing it to others everywhere. Therefore, the address we see now is a shorter public key generated by the digest algorithm.

The other party can send you money only if they know your address; moreover, anyone who has your address can check the number of transactions (No. Transactions) of this wallet address on the official website of Blockchain.info, and receive How many Bitcoins have been received (Total Received), and how many Bitcoins are left in the wallet (Final Balance), as shown below:

"Private key" is like a bank card that cannot be told to others. password. It is a string of 256-bit random numbers. Because it is particularly inhumane for non-IT users to remember this binary private key full of 0s and 1s, this large string of private keys was processed, and the final private key was a string starting with 5/K/L presented before us.

The relationship between public key, private key and address is:

1) Private key → public key → address

The private key generates a unique corresponding public key key, and the public key generates a unique corresponding address;

2) Private key encryption, public key decryption

In other words, A uses the private key to encrypt the transaction information (digital signature ), B uses A's public key to decrypt the digital signature.

Among them, the private key is an extremely private thing. If you send your private key to someone else, start writing a novel now. The name has been decided for you, and it will be called "Farewell, Bitcoin."

If you are a big man in the currency circle like Mr. Li Xiaolai (who is said to own hundreds of thousands of BTC on the Internet), it is strongly recommended to use a cold wallet (offline wallet) and store it separately; the rich people on TV have their own in the bank Safes can also be used as a reference if conditions permit.

At that time, the above method was the safest approach. But as the successor of Leek, let’s assume for the moment that we only use idle funds and hold a small number of Bitcoins, for example, less than 5. Then, cold wallets that cost thousands and are complex to operate are a bit overkill; therefore, Blockchain Observation Network limits the selection to exchanges and light wallets:

On the trading platformIf you buy (a very small amount of) Bitcoin on the exchange, you can continue to store it on the exchange without withdrawing it. This method is most suitable for newbies in the currency circle. Before we have a deep understanding of the story behind each cryptocurrency, we are always full of curiosity. Bitcoins placed on the exchange can be directly traded. The transaction is simple and fast, without the need to go through a digital wallet. ; On the other hand, the platform has a complete range of currencies, which can satisfy our early adopter mentality and make it easy to try out our skills at any time.

Moreover, large exchanges such as Huobi and Binance (which have been blocked) not only have a much higher security level than some small platforms designed to harvest leeks, but are also simple to operate and can be used quickly. To get started, you only need to keep your account and password safe (for a higher level of security, turn on Google two-step verification), and leave the rest to the platform.

It is worth noting that the assets stored on the exchange do not entirely belong to ourselves, but rather are lent to the platform. The number we see in the asset column is equivalent to the platform providing us with A white note for borrowing money. In addition, the trading platform itself is not decentralized. If security measures are not in place, users’ account passwords may be obtained by hackers.

Light wallets are relative to "full node" wallets.

Full-node wallets, such as Bitcoin-Core (core wallet), need to synchronize all blockchain data when running, occupy a considerable amount of memory space (currently at least 50GB or more), and are completely decentralized;

Although the light wallet also relies on other full nodes on the Bitcoin network, it only synchronizes transaction data related to itself, basically achieving decentralization and improving user experience.

According to different device types, we divide light wallets into:

1) PC wallet: suitable for computer desktop operating systems (such as Windows/MacOS/Linus);

2) Mobile wallet: suitable for Android and iOS smartphones, such as Bitether wallet (Ethereum also has a PC version);

3) Web wallet: accessed through a browser, such as mentioned above The web version of blockchain.

Light wallets are relatively simple to operate and are generally available for free. When applying for a wallet, the system will generate a private key. Get ready to hit the blackboard!

1) Do not take screenshots or photos and store them in your mobile phone;

2) Do not send private key information to anyone;

3) It is best to handwrite (a few words) copy) and hide it where you feel safest.

In a word, whoever masters the private key of the wallet has absolute control of the wallet. As long as the private key is in your hands, your Bitcoins will never be lost.

Finally, a few words. As ordinary investors, we don’t need to do much:

1) Take a snack and don’t lose your phone. After all,Losing the Bitcoin wallet on your mobile phone is risky;

2) Don’t delete the wallet application on your device. Unless you decide not to use this wallet anymore, it will be very troublesome later;

3) Set a complex password (see point 1 for the reason) and remember it carefully. This is what you will keep if the private key is lost.

For those of you who can’t remember your password and are too lazy to back up your private key scientifically, let’s just keep the money in the bank.

『8』 The difference and application of public keys and private keys.

In real life, if I want to transfer 1 Bitcoin to Yiyi, I need to enter my Bitcoin wallet address and Yiyi’s wallet on the Bitcoin trading platform, Bitcoin wallet or Bitcoin client. Address, amount of Bitcoin transferred, and handling fee. Then, we wait for about ten minutes. After the miner processes the transaction information, the 1 Bitcoin is successfully transferred to Yiyi.

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

Let’s talk about it today.

For the transferor and the receiver, that is, Yiyi and I (I am the transferor and Yiyi is the receiver), we both need to produce two things: wallet address and private key.

Let’s talk about the wallet address first. A Bitcoin wallet address is actually equivalent to a bank card, Alipay account, or WeChat wallet account. It is the "voucher" for Bitcoin payment transfers, recording transfer information between platforms, wallets, and wallets.

When we use bank cards, Alipay, and WeChat transfers, we need passwords to make successful payments. Well, in Bitcoin transfers, there is also such a "password", and this "password" is called the "private key". Once you master the private key, you have the power of life and death on its corresponding Bitcoin address.

"Private key" is a concept in the "asymmetric encryption algorithm", and there is another concept corresponding to it, called: "public key".

We can understand the public key and private key from the literal meaning: the public key can be made public; while the private key is private, owned by you, and needs to be kept absolutely confidential.

The public key is calculated based on the private key. The Bitcoin system uses the elliptic curve encryption algorithm to calculate the public key based on the private key. This creates a unique correspondence between the public key and the private key: when you use one of the keys to encrypt information, only the matching other key can decrypt it. Therefore, it is based on this unique corresponding relationship that they can be used to verify the identity of the information sender and achieve absolute confidentiality.

Let’s take an example to talk about, in the asymmetric encryption algorithm, how public and private keys work.

We know that the public key can be made public, so everyone knows our public key. During the transfer process, I not only have to ensure that the bitcoins are transferred to Yiyi and not to anyone else, but I also have to let Yiyi know that these bitcoins were transferred to her by me, not Lulu or Brother Ji.

The Bitcoin system can meet my above demands: the 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, the digital signature can prove my identity.

After completion, the complete transaction information and digital signature will be broadcast to the miners. The miners will use my public key to verify and see if my public key and my digital signature can match. If If the verification is successful and there is no problem, it means that this transaction was indeed sent by me and the information has not been changed.

Next, the miner needs to verify whether the Bitcoin spent in this transaction is an "unspent" transaction. If the verification is successful, it will be put into "Unconfirmed Transaction" and wait to be packaged; 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 it is encrypted, I definitely 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, the private key is responsible for decryption; similarly, since it is a signature, I definitely don’t want anyone to pretend to be my identity. Only I can issue 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 content. Above we mainly talked about the following words: private key, public key, wallet address, digital signature. Let’s understand the relationship between them:

(1) The private key is randomly generated by the system. The public key is calculated from the private key, and the wallet address is calculated from the public key, that is: private key - public key - wallet address, such a process;

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

Private keys and public keys are both in the category of cryptography and belong to the "elliptical encryption algorithm" in the "asymmetric encryption" algorithm. The reason why this algorithm is used is to ensure the security of transactions. 2. The role of the operator is:

(1) Public key encryption, private key decryption: the public key is public to the entire network, I use Yiyi’s public key to encrypt the information, and Yiyi can decrypt it with her own private key;< br />
(2) Private key signature, public key verification: I sent a message to Yiyi, and I added my own private key information to form a digital signature. Yiyi used my public key to verify it, and the verification was successful.It proves that it is indeed the message I sent.

It’s just that in Bitcoin transactions, encryption, decryption, and verification are all left to the miners.

As for the wallet APP we often use now, it is just a management tool for private keys, wallet addresses and other blockchain data. Wallets are divided into cold wallets and hot wallets. Cold wallets are offline and never connected to the Internet. They usually appear in the form of some entities, such as small notebooks. Hot wallets are connected to the Internet, and the wallet APP we use is a hot wallet. .

博客主人唯心底涂
男,单身,无聊上班族,闲着没事喜欢研究股票,无时无刻分享股票入门基础知识,资深技术宅。
  • 37647 文章总数
  • 3637286访问次数
  • 3081建站天数