Surely the public blockchains need to know what your password is in order to confirm that it is correct? But then, couldn’t someone figure out your password by looking at the blockchain data, which is all completely public?
To understand the reason, you need to know a bit about public key cryptography.
Imagine that you want to secretly tell me that your age is “65”. I send you my public key (which has two parts, 17 and 3233) and you perform the calculation:
65^7 mod 3233 = 2790
You combine the secret message with both parts of my public key and the result is the encrypted message. Then you send me only the code number “2790”.
Then when I receive that message, I perform the reverse calculation:
2790^413 mod 3233 = 65
I combine the encrypted message with my private key and the second part of my public key and the result is the unecrypted message.
Then I know your secret age 65.
Nobody who intercepts the code number “2790” can decode it in the same way, because they need to know that exponent “413” which reverses the calculation.
Figuring out the right exponent requires a process of guess-and-checking which takes too long even with a powerful computer.
That is similar to the process of finding a new Bitcoin block, which uses powerful, specialized hardware to guess and check more than 10 trillion possible answers every second. Finding the correct answer gives the equipment owner at least $160,000 worth of Bitcoin (depending on the prevailing market price), but takes approximately one year of constant 24-hour processing to achieve.
A new public key is generated by multiplying two numbers together.
In this case I chose 61 and 53.
61 x 53 = 3233
I multiply them together and get 3233, which is the second part of my public key in this example.
The first part of the public key can be chosen as you like. In this example I chose the number 17.
A new private key is generated by performing a computation called a “totient” (you don’t need to know what that means) on the seed numbers and the second part of the public key, which gives the result “413”, the private key in this example.
Only I can perform this calculation, because the seed numbers are never shared with anyone else. Only the two parts of the public key (3233 and 17) are ever shared.
It is necessary to make the encryption equation public so that everyone can send me encrypted messages. But nobody but me can decrypt them because only I have the private exponent number to reverse the equation.
The Public blockchain knows the equation, your public key, and what the correct answer should be, but it doesn’t know the right exponent which gives the correct answer, and it takes too long to guess and check.
That is your private key. Guard it with your life.