What are Public and Private Keys in Blockchain?
The multiplicative inverse and the public and private keys
In mathematics, a multiplicative or reciprocal inverse for a number X is: 1/ X
So, the inverse of 5 is 1/5, so that (5) (1/5) = 1
In article 5 of this cryptography series, we learned with modular mathematics how to send an encrypted message with two exponential functions in a modular format:
function to encrypt: C = me module n
function to decipher m = Cd modulo n, where:
e= is the public key
d= is the private key
In addition, "e" and "d" meet the condition of being multiplicative inverses in module "n".
(e) (d) mod n= 1
Example: If e= 17 and “d” are multiplicative inverses in the module n= 589.
To find the value of “d”:
Find two prime numbers that when multiplied give 589.
These are p=19 and q=31 because (19)(31) = 589.
Euler's theorem says that in the value of the function φ(n)= (p-1) (q-1) I can find two numbers that are multiplicative inverses.
So (19-1) (31-1) = 540
Use an online site: Inverse Multiplicative Modular put e=17 and n=540
We have found the private key d= 413 that corresponds to the public key e= 17, because:
We know the value of the module n = 589.
We easily find the multiplicative inverse numbers “e” and “d” in the module φ(n) = 540.
In practice Bitcoin cryptography uses the math in modulus “n”:
115792089237316195423570985008687907853269984665640564039457584007908834671663
Examples of Bitcoin private keys:
With the Bitcoin programming in Python language select random numbers within this module, here we illustrate three private keys s1, s2 and s3:
Examples of public keys:
Multiply these numbers by the generating point of the elliptic curve G and obtain the public keys s1G, s2G and s3G. These keys are in uncompressed format:
Online platforms to obtain keys
There are online sites that allow you to generate keys, click start: Generator
These keys are in compressed format:
Bitcoin Address:
1PGBivpWXTUvEdXZ6FGzXzrSGvc11zpWs8
Private key:
L2SpQKmESVNmcZB3aKyhVRmQNM5uRgd64LERi8sEjTgjiM1Wno3L
Application of the keys
Bitcoin programming
Step 1: have a public key (Address) and its corresponding private key:
Private key:
L1d2uVdAobUjTBU84qB8KWUR13W2wvnDGQcHLpCk85RiUW5gU55u
Address:
36e4yeKShaHEwLQYDDbNE9U4fWR1PEVtAX
Step 2: Bob wants to send a message to Alice so that Alice can verify that it is from Bob:
Step 3: Message or plain text:
New York City is the most populous city in the United States. With a 2020 population of 8,804,190 spread over 300.46 square miles, New York City is also the most densely populated major city in the United States.
Step 4: Use a program in JavaScript language of the Bitcoin protocol, to sign the message (encrypt or encrypt):
On line 3 in the plaintext variable place the message.
On line 4 is the private key.
On line 7 sign the message.
Step 5: Running the program in the Microsoft git bash terminal, I get the ciphertext:
Message Cyphertext=
H1E8apbIZ4plJ8Hx44t+TahH2skW9EV142PXYUKLHdSVJ47bQ0+g6OJlt3KXA89hNHY0QmUQkYXoH/pYfZAhZv8=
Step 6: Alice receives by email:
The message (plain text)
The ciphertext.
In addition, he knows Roberto's public key or address.
Run the digital signature verification program in JavaScript of the Bitcoin protocol:
And when running the program on her terminal git bash, Alice gets a “true” response.
Conclusion:
Public and private key cryptography allows signing messages and verifying that they correspond to the person who sent them. This process, called authentication, prevents an attacker from sending malicious messages within a computer system network.