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. In other words, KA = P, where P is a coordinate point on the curve. In Bitcoin, there is a recognized point G that plays the role of point A, meaning that the random point is public, and G is like a constant.
Message Encryption#
NP problem: Given P and G, it is difficult to find K, 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 keys are public. This means that both 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 message to Bob, she encrypts the message using Pb, and Bob decrypts it using Kb, performing 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 is easy to verify whether m is what Alice said.