CENTRO DE AYUDA
Basics of Blockchain 3 – A Bitcoin Private Key
Publicar el 2022-02-07
What Is a Bitcoin Private Key?
Private keys are a crucial part of how Bitcoin (BTC) and other cryptocurrencies work.
Bitcoin uses cryptography to create a key pair that controls access to Bitcoin on the blockchain. Each Bitcoin key pair consists of a public and private key. Bitcoin private/public keys are not actually stored on the Bitcoin network, but in a wallet file or a simple database. The Bitcoin private key is generated from and managed by the user’ wallet software, without need to refer to the blockchain or visit the network.
Bitcoin private/public keys play an important role in ensuring the decentralized trust, control, ownership verification and security performance of Bitcoin.
A Bitcoin Private Key
A Bitcoin private key is usually a 256-bit randomly generated number. Consider a coin with the front and back being marked with 0 and 1, respectively. The random number is generated by tossing the coin 256 times.
How is a random number generated?
Generally, a Bitcoin private key can be generated in two steps: a random number generation + SHA-256 hash algorithm. Generating a random number is the first and the most significant step towards generating a Bitcoin private key, which essentially is to find the source of randomness that is secure enough. In effect, generating a Bitcoin private key consists of selecting a random number between 1 and 2^256 on the condition that the selected result is unpredictable or unrepeatable. To be more precise, a Bitcoin private key can be any number between 1 and n-1 (n is a constant number. n=1.158*10^77,slightly smaller than 2^256). Specifically, Bitcoin uses the random number generator in its underlying operating system as the randomness source to pick a string of random bytes before proceeding to SHA-256 hash algorithm operations to generate a 256-bit number. If the result is less than n-1, the number will be a private key, or a new random number will be picked for a recalculation.
Please see below for a common Bitcoin private key:
Different from what we mentioned above, the private key is not a 256-bit number. It is actually a variant of a 256-bit random number. If it’s shown in the form of a 256-bit number, it will have a low recognition rate and an excessive length. Therefore, a 256-bit random number is usually displayed in hexadecimal - 256 bits in hexadecimal is 32 bytes.
As mentioned above, the upper limit of a Bitcoin private key is 2^256, which is tremendous enough to far exceed the total number of atoms in the entire Milky way galaxy, so it’s impossible to try every private key. Bitcoin private keys contributes to cryptographic security, which is guaranteed by mathematics.
The function of a Bitcoin private key is to generate a digital signature for transactions and verify the true owner of Bitcoins. In other words, assume that you have 10 BTC, the Bitcoin private key you keep is the only proof verifying you are the true owner of the asset. Due to the ownership verification feature, the private key must always remain secret because revealing it to third parties is equivalent to giving them control over the Bitcoins secured by that key. The private key must also be backed up and protected from accidental loss, because if it’s lost it cannot be recovered and the funds secured by it are forever lost, too.
A Bitcoin Public Key
A Bitcoin public key is generated from the corresponding private key. Specifically, a Bitcoin public key is generated from the corresponding private key using a multiplication on an elliptic curve. Please see below for the calculation formula:
The private key (k) will be multiplied by a point generator (G) located on the curve and the result will correspond to the public key (K).
Noticeably, the above calculation process is irreversible, which means it is very difficult to reversely calculate the above formula (also known as finding a discrete logarithm), that is, it is very difficult to solve the private key (k) by knowing the public key (K), because this is equivalent to testing all possible k values. This special process is credited to the characteristics of the elliptic curve multiplication algorithm.
Elliptic curve multiplication is what cryptographers call a function with the "trap gate", that is, it is easy to calculate in one direction (by multiplication), but not in the opposite direction (by division). Using the Elliptic Curve Digital Signature Algorithm, a private key can be easily used to create a public key, but the private key can’t be deduced from the public key, which ensures the unforgeability of the Bitcoin private key.
A private key is used as a digital signature for Bitcoin transactions, while a public key is mainly used to verify Bitcoin transactions. The role of a public key in verifying Bitcoin transactions includes: 1) the public key generates addresses to verify whether the address of a transaction is the same as the address the public key generated for the transaction 2) The public key verifies the signature of the private key, which is used to verify that the transaction is signed with the correct private key.
A Bitcoin Address
A Bitcoin address is a string of alphanumeric numbers that can be shared with anyone.
The Bitcoin address is not the same as the public key. Bitcoin addresses are generated by the public key through an encrypted hash algorithm. The hash algorithm is a one-way function that can receive input of any length to generate fingerprints or hashes. Bitcoin addresses are generated from the public key using SHA256 and RIPEMD160 hash algorithms. Please see below for the calculation formula:
Where K is the public key and A is the generated Bitcoin address. Specifically, take the public key K as the input to calculate K’s hash value using SHA256 hash algorithm, based on which the RIPEMD160 hash value is calculated, and a 160-bit number (of 20 bytes) is obtained.
The commonly seen Bitcoin addresses are in the “Base58Check" encoding format, which uses 58 characters (a Base58 encoding format) and a check code to improve readability, avoid ambiguity, and effectively prevent errors in address transcription and input. Common Bitcoin addresses are as follows:
Within Bitcoin transactions, addresses usually act as receivers of the Bitcoins, and their existence allow for more flexible transactions.
In general, the relationship between a Bitcoin private key, public key and address can be summed up in the following figure:
That is, based on the private key k, we can use the elliptic curve multiplication to generate a corresponding public key K. Based on this, we can use the one-way encrypted hashing function to generate the Bitcoin address A. The whole process is irreversible. The public key K can only be calculated from the private key k, thus generating the address A, while the public key K and the private key k can’t be deduced from address A.
It is important to note that both public and private keys can be in multiple formats. Although they may look different, they are encoded with the same number. These different encoding formats are mainly used to facilitate people to read, identify and store.