What is the difference between Private Keys and Public Keys?
Cryptography - Encryption and decryption
In this article about crypto wallets, we briefly mentioned that cryptocurrencies are secured by a process called cryptography. Cryptography is the technique of securing information and communication through the use of code. It works by encryption and decryption. With Encryption - a message is scrambled into an unreadable format and sent to the reader, who unscrambles it back to a readable format by decryption using a secret key.
Symmetric vs Asymmetric Encryption
In blockchain technology, cryptography is achieved using specific encryption algorithms. These algorithms are divided into two categories known as symmetric and asymmetric encryption systems.
The major difference between both systems is that the symmetric system uses one key to encrypt and decrypt the message. In contrast, the asymmetric system uses two separate but related keys for encryption and decryption.
To illustrate how this works, let’s imagine that two friends, Michael and Jan, decide to stay in touch with each other by frequently sending emails. They each have access to one computer, which is publicly shared by their respective friends and family.
Michael suggests that they secure their messages via symmetric encryption to ensure that their messages are private. He then creates a secret key and shares it with Jan. They both use this until Jan’s mischievous brother discovers the key and can also read their messages.
Jan then suggests that they try an asymmetric encryption method, where they both create a public and private key pair. They exchange their public keys with each other and use them to encrypt their messages. When Jan messages Michael, she encrypts the message with his public key so that he can decrypt and read it using his own private key. With this example, we hope that you now understand how both encryption systems work. Now, let’s explore the public and private keys in detail.
In cryptocurrencies, public keys allow you to receive transactions. They are like your traditional bank account number. Anyone who has it can only use it to send money to you. To access your money, you need your banking login details similar to your private key. You can freely share your public key with anyone for the purpose of receiving payments.
If there’s only one thing that you can take away from this article, it is that you must never share your private key with anyone. A private key is the ultimate proof of ownership - that the funds in your wallet are yours and you can spend them. If anyone takes custody of your private keys, they automatically take over your funds.
Private keys can come in any of the following forms;
- 256 character long binary code
- 64 digit hexadecimal code
- QR code
- Mnemonic/seed phrase
How Public and Private Keys Work in Crypto
When you claim ownership of some cryptocurrencies, it means that you own the private keys to prove ownership. Because it is recorded on the blockchain, anyone can ascertain your claim using your public key.
Public and Private Keys for Digital Signature
To complete a blockchain transaction, the transaction needs to be signed. Here are the steps for sending a transaction
- You encrypt the transaction using the receiver's public key. The receiver will decrypt this transaction using their private key.
- To prove the transaction's authenticity, you sign off using your private key. The digital signature is generated by combining your private key and the data of the transaction.
- Finally, the authenticity of the transaction is confirmed using your public key.
How to find your private key
If at this point, you are beginning to wonder where your private key is, it is in your cryptocurrency wallet. If you are using a centralized cryptocurrency exchange like Binance or Coinbase, then the exchange is the custodian of your private key. You are trusting them with your private key in the same way that you trust the bank with your money. The advantage of this is that it can be convenient for you not to worry about the security of your private key, but if the exchange is hacked and the attacker takes hold of your private key, you will lose your funds.
With decentralized crypto wallets like Metamask and cold storage hardware wallets, you take custody of your private key. It comes in the form of a seed phrase that you must keep secure at all times or risk losing your funds.