The nature of cryptocurrency ,Where is the Bitcoin private key

This time, using compressed format is an example 6954ac6d0402d7239f1cc150da224d0ef08fd1226f245f06fe4d6d68accfce8a01 Then the private key is base58checkcoding ,That is, convert to WIF(Wallet Import Format)Format Add version prefix before private key ,0x80for WIFPrefix 806954ac6d0402d7239f1cc150da224d0ef08fd1226

As a representative of cryptocurrency ,It is also the world's first and largest cryptocurrency ,Understanding the nature of Bitcoin will also understand the principles of most cryptocurrencies 。So where is the Bitcoin private key ?Bitcoin contains a series of key pairs ,Each key pair contains a public and private key ,Bring a detailed explanation now 。
one 、What is a Bitcoin private key ?
The private key can be understood as a random number ,The control of funds in a Bitcoin address depends on the control rights of the corresponding private key ,Bitcoin trading ,Private keys are used to generate the signature necessary to pay Bitcoin to prove ownership of funds 。
Select a random source (Source of entropy ),Generate a Bitcoin private key in essence with “exist 1arrive22562256Choose a number between ”No different 。Cryptographically secure pseudo-random number generator is recommended (CSPRNG),And there needs to be a seed from a source with sufficient entropy value 。
two 、What is the Bitcoin public key ?
The elliptic curve algorithm can generate the public key from the private key ,This process is an irreversible process :K(Public Key )=k(Private key )*G(Constant Point )。Its reverse operation ,Called “Finding discrete logarithms ”–Known public keys KFind the private key k–It's extremely difficult 。

three 、What is the principle of generating Bitcoin keys ?
Elliptic curve encryption method is asymmetric based on discrete logarithmic problem (or public key )Encryption method ,It can be expressed by adding or multiplying points on an elliptic curve. 。
Start by generating a random number through the operating system random number generator ,And carry out SHA256Hash operation (The result must be 1arriven-1Any number between ,n=1.158 * 1077),This number is the original content of the private key ,Therefore, it is necessary to select a string of random bytes from a cryptographically secure random source ,To prevent brute force cracking SHA256Hash operation is to facilitate the generation of a fixed length 256Number of bits ,Use hexadecimal to express it as follows :6954ac6d0402d7239f1cc150da224d0ef08fd1226f245f06fe4d6d68accfce8a
If the compressed public key is used ,Add after the result of the private key 0x01;If using a non-compressed public key ,No additional 0x01.Suffix of private key 01Used to tell the wallet's private key to whether the public key and address are compressed or non-compressed. 。The reason is that the compressed public key of the same private key is different from the non-compressed public key. ,The generated address is also completely different ,That is to say, there will be two public keys and two addresses corresponding to a private key. ,If there is no logo ,The wallet cannot correspond to the private key and the public key and the address one by one. 。This time, using compressed format is an example
6954ac6d0402d7239f1cc150da224d0ef08fd1226f245f06fe4d6d68accfce8a01
Then the private key is base58checkcoding ,That is, convert to WIF(Wallet Import Format)Format
Add version prefix before private key ,0x80for WIFPrefix
806954ac6d0402d7239f1cc150da224d0ef08fd1226f245f06fe4d6d68accfce8a01
Make the above results double-SHA256After the calculation, take the first four bytes as the verification code and splice it at the end ,Then proceed base58Encoding to obtain the final form of the private key (No WIFThe result prefix of the compression format is 5.WIFThe result prefix of the compression format is Kor L)KzkTe43L5cbSX64txJMcsFvJC6vov7nYaGdYicz5N8Mds4ThN2XM
Then use secp256k1Elliptic curve algorithm converts private keys to public keys (Gx,Gy),Elliptic curve algorithm is an asymmetric encryption method based on discrete logarithmic problem ,Its mathematical operations are one-way ,So the private key can be converted into a public key ,But the public key cannot be converted back to the private key ,After converting the above results, we will get the following results (hexadecimal ):(0ba1ba3b8d8f7bd4a70828ec0e749dd26ee4cdd18d058c880afa121fad60e5b6.f2ee1b72d9b9a57706e5de72acc1378f92269086c4964c073593bf92d28c647d)
Merge public keys into hexadecimal numbers
Compressing the public key can greatly save the space occupied by the public key (reduce 256bits),It is the current default format of Bitcoin client ,And it is also compatible with non-compressed public keys ,Uncompressed (Prefix 04.Will Gx,GySplicing )
040ba1ba3b8d8f7bd4a70828ec0e749dd26ee4cdd18d058c880afa121fad60e5b6f2ee1b72d9b9a57706e5de72acc1378f92269086c4964c073593bf92d28c647d
compression (yPrefixes with even numbers 02.yAn odd prefix 03.Keep only Gx,GyAvailable Gxcalculate )
030ba1ba3b8d8f7bd4a70828ec0e749dd26ee4cdd18d058c880afa121fad60e5b6
After this, the public key can be converted to a Bitcoin address
1.RIPEMD160(SHA256(Public Key ))Got it 20byte /160 bitsPublic key hash ,Use two types of HashThe biggest benefit of function conversion is if one of the functions is cracked ,Still guaranteed safety 。
2.Perform public key hashing Base58checkcoding (Version prefix + Public key hash + SHA256(SHA256(Version prefix +Public key hash ))forward 4Bytes Base58coding ),Here is P2PKHaddress ,The prefix is 0x00.The final bitcoin address is as follows :17FjrmErg5a39P7UsyYCchpyzSnq9gmMuJ

Four 、summary
The private key is a random number ,The private key generates the public key through the elliptic curve algorithm ,The public key then generates the Bitcoin address through a one-way cryptographic hash function. 。Bitcoin uses asymmetric encryption ,Make the signature only generated by the private key ,And without leaking the private key, everyone can verify the signature p。Private and public keys can be encoded into various types of formats ,The purpose of this is to facilitate identification and wallet operation 。
Original title : The nature of cryptocurrency ,Where is the Bitcoin private key
Original website :https://www.financialks.tw/en/block-chain/2396.html