Private Keys, Public Keys, and Addresses
Tags: ethereum, cryptography, security
Published: 2023-06-19 21:59:40

---
title: Private Keys, Public Keys, and Addresses
published: true
date: 2023-06-18 17:00:00 UTC
tags: Ethereum,Cryptography,Security
canonical_url: https://byteatati.me/keys-and-addresses
---

 This post was originally published **[on my blog!](https://byteatati.me/blog/keys-and-addresses)**

* * *

Welcome back! You’ve likely heard of private keys, public keys, and addresses, but what are they, and how do they work together? Today, we’re going to explore the relationship between these cryptographic values and discover how they interact with each other.

<svg style="height:1em;font-size:3em;vertical-align:-.125em;transform-origin:center;overflow:visible" viewbox="0 0 512 512" aria-hidden="true" role="img" xmlns="http://www.w3.org/2000/svg"><g transform="translate(256 256)" transform-origin="128 0"><g transform="translate(0,0) scale(1,1)"><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336h24V272H216c-13.3 0-24-10.7-24-24s10.7-24 24-24h48c13.3 0 24 10.7 24 24v88h8c13.3 0 24 10.7 24 24s-10.7 24-24 24H216c-13.3 0-24-10.7-24-24s10.7-24 24-24zm40-208a32 32 0 1 1 0 64 32 32 0 1 1 0-64z" fill="currentColor" transform="translate(-256 -256)"></path></g></g></svg>

This article contains references to `secp256k1`, which is the elliptic curve used in both Bitcoin and Ethereum. I will be covering this in a later blog post.

## Private Keys: Your Digital Secret

At the core of your Ethereum account is a private key, a 256-bit random number that serves as your digital secret. It is used to sign transactions and messages, proving that you are the owner of the account. If someone else has access to your private key, they can sign transactions on your behalf, effectively taking control of your account.

More specifically, a private key is a randomly generated number between the values `0x01` and`0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140`. This range is known as the `secp256k1` curve order, which is the order of the elliptic curve used in Ethereum’s cryptography.

<svg style="height:1em;font-size:3em;vertical-align:-.125em;transform-origin:center;overflow:visible" viewbox="0 0 512 512" aria-hidden="true" role="img" xmlns="http://www.w3.org/2000/svg"><g transform="translate(256 256)" transform-origin="128 0"><g transform="translate(0,0) scale(1,1)"><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336h24V272H216c-13.3 0-24-10.7-24-24s10.7-24 24-24h48c13.3 0 24 10.7 24 24v88h8c13.3 0 24 10.7 24 24s-10.7 24-24 24H216c-13.3 0-24-10.7-24-24s10.7-24 24-24zm40-208a32 32 0 1 1 0 64 32 32 0 1 1 0-64z" fill="currentColor" transform="translate(-256 -256)"></path></g></g></svg>

It is important that the private key is generated using a cryptographically secure random number generator. Do not generate it using a programming language's standard library!

## Public Keys: Sharing Your Digital Identity

Derived from the private key, a public key is a cryptographic value that serves as your digital identity on the Ethereum network. Unlike the private key, the public key can be shared freely without compromising the security of your assets. It is used to verify digital signatures and encrypt messages intended for you.

Because of the nature of how cryptography works, your public key can be used to verify that you are the sender of a transaction or message. However, it cannot be used to derive your private key or forge a signature.

To get a public key from a private key, we use a process called elliptic curve cryptography. This process involves multiplying the private key by a special value called the generator point, resulting in a public key. The generator point is a constant value that is defined by the `secp256k1` curve.

## Addresses: Your User-Friendly Identifier

An Ethereum address is a 160-bit (40 character HEX) value that is derived from the public key. It is used to identify your account on the Ethereum network. Addresses are a shorter, more user-friendly representation of public keys, which are long and difficult to remember (not that you could memorize 40 characters, anyway).

To derive an address from a public key, we get the last 20 bytes (40 chars) of the `KECCAK-256` hash of the public key.

## Security Best Practices

To ensure the security of your Ethereum holdings, it is crucial to follow these best practices:

- **Protect Your Private Key** : Keep your private key secure and never share it with anyone. Store it in a secure offline environment, such as a hardware wallet or a secure digital storage medium. **Treat your private key as cash of equal value as your cryptocurrencies!**

- **Use Hardware Wallets** : Consider using a hardware wallet, a physical device specifically designed for storing private keys securely. Hardware wallets provide an extra layer of protection against online threats.

- **Backup Your Private Key** : Make backups of your private key and store them in multiple secure locations. This ensures that you can recover your assets in case of hardware failure or loss.

- **Be Cautious Online** : Beware of phishing attempts and malicious websites that may try to trick you into revealing your private key or personal information. Always verify the authenticity of the websites and applications you use to interact with Ethereum.

## Conclusion

While private keys, public keys, and addresses are low-level concepts, they are crucial to understanding how Ethereum works. They are the foundation of your Ethereum account and are used to sign transactions and messages. By following security best practices, you can ensure that your assets are safe and secure.