A public key is used for encrypting data or verifying digital signatures, and it can be shared with anyone. In contrast, a private key is used for decrypting data or creating digital signatures, and it must be kept secret and never shared with others. The public key is used to encrypt the data, and only the corresponding private key can decrypt it.