How to generate an address? What is asymmetric encryption?
Steps to Generate an Address#
- Randomly generate a 256-bit private key (32 bytes).
- Obtain the public key through elliptic curve encryption.
- Apply two hash functions to the public key to generate a 20-byte address.
Elliptic Curve#
Where K is the private key and P is the public key.
Take a random point A(x, y) on the curve and calculate Kx+Ky equals P. That is, KA=P, and P is actually a coordinate point on the curve. In Bitcoin, there is a recognized point G that plays the role of point A, which means the random point is public, and G is like a constant.
Message Encryption#
NP problem: It is difficult to find out K given P and G, but it is easy to verify that P is correct based on K and G.
There are two people, Alice and Bob, each with their own public and private keys.
- Alice: Pa Ka
- Bob: Pb Kb
Pa = Ka * G
Pb = Kb * G
The public key is public. That is, the two parties can also know the other person's information.
- Alice: Ka * Pb = Ka * Kb * G
- Bob: Kb * Pa = Kb * Ka * G
These two pieces of information are equal, which means they have the same key. This key can be considered as a symmetric key that belongs only to these two individuals.
When Alice wants to write a letter to Bob, she encrypts the information with Pb, and Bob decrypts it with Kb, which is a reversible operation.
Digital Signature#
m: message
Alice signs m with Ka, m * Ka = N, similar to generating a public key with a private key (m is G).
The other party wants to verify that this statement was made by Alice.
m * Pa = m * G * Ka, which is equal to G * N. Since G is public, it can be quickly verified whether m is what Alice said.