A public key and a private key are both components of public-key cryptography, but they serve different purposes. A public key is shared with others and used to encrypt data or verify digital signatures, while a private key is kept secret and used to decrypt data or sign digital messages. The key pair is generated together, ensuring that data encrypted with one key can only be decrypted with the other key.