What is a public key
A public key is a cryptographically generated string of numbers and letters. As the name implies, it can be shared publicly to facilitate transaction verification, message encryption, and user authentication.
It works in tandem with a private key forming a key pair that is critical not only to maintaining the integrity and trustless nature of decentralized networks but also to preserving user privacy. This allows users to share their public key freely, enabling interactions without exposing their private key or risking unauthorized access to their assets.
Sharing a public key does not pose a security risk, as it is generated from the private key using cryptographic techniques that make reversing the process virtually impossible when proper standards are applied.
The function of public keys
A public key fulfills several roles in blockchain networks:
- Encryption: Data encrypted with the public key can only be decrypted by the holder of the corresponding private key. This preserves confidentiality in message exchanges or file transfers over public networks.
- Transaction verification: When a transaction is signed using a private key, the public key can validate that signature without exposing the private key. Trustless verification allows nodes in a blockchain network to confirm the authenticity of each transaction.
- Ownership confirmation: Public keys help confirm a user’s ownership in decentralized apps (dApps), ensuring that only the rightful holder of the corresponding private key can perform specific actions.
How a public key is generated
This process applies to most blockchain ecosystems (such as Ethereum):
- Private key creation: A user’s wallet generates a 256-bit number with a cryptographically secure pseudo-random number generator (CSPRNG).
- Elliptic curve multiplication: That private key is multiplied by a base point on the secp256k1 elliptic curve to produce the uncompressed public key (65 bytes).
- Compression or hashing: Many implementations compress or hash the uncompressed public key to reduce storage requirements, resulting in a 33-byte compressed form or 20-byte address in Ethereum.
What are public keys used for
- Verifying transactions: Validating that each transaction has been signed by the correct private key.
- Encrypting messages: Ensuring only the intended private key holder can decrypt sensitive information.
- Generating wallet addresses: Deriving unique on-chain destinations for sending tokens, non-fungible tokens (NFTs), or other digital assets.
- Digital signatures: Authenticating software packages, documents, or emails in other cryptographic protocols outside of blockchain.
Difference between a public key and an address
While often used interchangeably, a public key and an address are distinct elements in blockchain systems:
- A public key is the direct output of elliptic curve multiplication, 65 bytes in uncompressed form or 33 bytes if compressed.
- An address is a hashed and shortened version of the public key, formatted for easy reference within blockchain systems (e.g., a 20-byte address in Ethereum starting with 0x).
- The address serves as a user-friendly identifier, whereas the raw public key contains more information but is less commonly used for everyday transactions.
Example of an Ethereum uncompressed public key
0x046B0D3A67A819BB5FFCB9E62AF1F86C2A9FBBE9A71F82064AF8036AC74F1640A04CA5895B06316CF63FF9123DC785F76D50299FE9E3B4BA7C2C34C6E91909F6EC
This is a 65-byte hexadecimal string, starting with 0x04 to denote uncompressed format. In practice, Ethereum addresses are derived by applying a Keccak256 hash to the last 64 bytes of this public key and taking the rightmost 20 bytes.
Example of an Ethereum address
0x742d35Cc6634C0532925a3b844Bc454E4438f44e
This 20-byte address is a shorter, user-friendly identifier of the uncompressed public key above. It is used by users of the network to send and receive tokens or interact with smart contracts. The address follows the Ethereum checksum format defined in EIP-55, using a mix of uppercase and lowercase letters to help detect typing errors. The checksum mechanism ensures mistyped addresses are likely detected as invalid, reducing the risk of accidental loss of funds. Ethereum wallets and block explorers widely support this format, offering an additional layer of error detection for secure transactions.