What is the private key, public key, and address

Source: Internet
Author: User
Tags hash


This is the three words that often appear in Bitcoin, so what do they mean by each other? What kind of relationship do they have?

Let's talk about a private key, such as a string 5KYZDUEO39Z3FPRTUX2QBBWGNNP5ZTD7YYR2SC1J299SBCNWJSS, which is a private key. Any application that correctly supports the Bitcoin protocol can recognize the string as a private key, convert it to a public key, convert it to an address, and, if there is bitcoin on the corresponding address, use the private key to spend the above bitcoin. The public key and address generation all depend on the private key, so the private key is the most important in the Bitcoin world, with the private key can generate the public key and address, you can spend the corresponding address above the bitcoin. The way the private key spends bitcoin is to sign (encrypt) the unused transactions owned by the private key.

The private key is essentially a 32 byte array, 1 byte equals 8 bit binary, one binary has only two possibilities 0 or 1, so the total number of private keys is 2^ (8*32) =2^256, this number has exceeded the total number of atoms in the universe, want to traverse all the private key, It is impossible to exhaust the energy of the whole sun. What we call Bitcoin private key is cryptography security above, it is not impossible to duplicate the private key, but it is impossible to traverse all the private key, or other way to find the private key with Bitcoin, so the private key is cryptography safe. The total number of private keys is large, but the private key generation is to rely on random, do not rely on random will greatly reduce the probability of generating a private key space, cryptography above the security of random refers to the random is not predictable, random results are not traversed. Cryptography secure randomly generated private keys can be used to store bitcoins, if randomly insecure, you can get the private key will be the same as others, then your bitcoin will be lost.

32 byte arrays are made up of 256 0 or 1, and if displayed, not only is the recognition rate too bad, but it is too long. So the private key will be converted to the look above, the above private key is a 32 byte array to do a Base58 conversion, Base58 is used in bitcoin for the use of a unique encoding method, mainly used to generate Bitcoin wallet address and private key. Compared to BASE64,BASE58 does not use the number "0", the letter Capital "O", the letter Capital "I", and the letter lowercase "l", as well as "+" and "/" symbol. Mainly for the naked eye easy to identify, in the input is not easy to hit the wrong, but I prefer to use two-dimensional code to scan the private key, after all, the above paragraph of the irregular string input is still very laborious.

We see the private key in addition to the beginning of 5, there are "L" and "K" the private key, why this situation occurs. What does 5,l,k represent? The content of this section is about the public key.

The public key is generated by the private key, generated by an elliptic curve (Ecpoint), and a private key is transformed into an array of 65 bytes after the Elliptic curve transformation. In general, we'll see a public key like this: 04A34B99F22C790C4E36B2B3C2C35A36DB06226E41C692FC82B8B56AC1C540C5BD5B8DEC5235A0FA8722476C7709C02559E3AA73AA 03918ba2d492eea75abea235, the public key is usually displayed after the hex (16 binary) processing of the byte array, unlike the Base58 of the private key,
The public key is used to unlock the private key signature of the data, after using the private key signature transaction, the public key will be sent together, the private key signature data can be decrypted with the public key, after sending the public key to verify the correctness of the signature of the private key (can be solved), the private key and the public key is a pair of data, Only the corresponding public key can be solved, and the address is generated from the public key, so you can verify that the transaction that is spent is not part of this address.

As for why there is a 5 start or l,k beginning of the private key, the problem is on the public key, the example of the private key contains not only 32 byte array of information, or the private key version of the information and public key is compressed information, the early Bitcoin developers did not know that the generated public key can be compressed, The compressed public key has only 33 bytes, and the uncompressed public key has 65 bytes. The compressed public key is more important to Bitcoin because Bitcoin is a centralized, peer-to-coinbase crypto currency, each node has a complete transaction record, and each transaction will send a public key, in addition to the ore-mining bitcoin, and the public key is supported in the compressed format, and the transaction data will be reduced by 32 bytes. This makes sense for the entire Bitcoin network, which reduces the amount of data in the entire Bitcoin network. When the private key is BASE58 encoded, the private key supporting the uncompressed public key is actually a 33-bit byte array, the first bit holds the version information, the current value is 128. The private key that supports compressing the public key is 34 bits, the same is the first bit is the version information, its value is also 128, and the extra one is the last byte is used to store whether the information is compressed, 1 is the public key to support the compression format, 5 of the private key is not supported in the compressed format of the private key, Both L and K begin with a private key that supports the compressed format.

Whether the public key is compressed in addition to the display of the private key, or the address has an impact.

Address is generated by the public key, see the address is BASE58 encoding processing, address generation more complex, said address before have to say hash160, address is generated by the public key, but the public key generated address will be a hash160. The process is to make a SHA256 of the public key first, then RIPEMD160 the resulting result, and then take 20 byte array from the result, in front of this 20-bit byte array plus a byte, that is, the address version information (currently 0) to get a key Hash (hash160), and then the key hash do two times sha-256 take the first 4 bits (Checksum), cheksum and key hash connection, and then Base58 conversion is the look of the address we see, That is to say, hash160 and addresses can be converted to each other.

A private key can have a compressed public key, and an uncompressed public key, each public key will generate an address, the above private key will have two addresses: 1HZWKJKEAOZFTSAJXDW6AKKXP45AGDIEZN (the public key is not compressed), 1F3SAM6ZTWLAUNJ7D38PGFXTP3RVEVTSBV (compressed public key), these two addresses are the address of this private key, the money above each address can be spent with this private key. However, most applications today are private keys that support the compressed format.

This will give you a simple introduction of a private key, public key and address.

@btc Sub-Fish

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.