Blog | G5 Cyber Security

Public Key Cryptography: Encryption & Decryption

TL;DR

No, you can’t use either key for both encryption and decryption in asymmetric (public-key) cryptography. The public key encrypts data, but only the corresponding private key decrypts it. Trying to use the public key to decrypt or the private key to encrypt will not work.

Understanding Asymmetric Cryptography

Asymmetric cryptography uses a pair of keys: a public key and a private key. These keys are mathematically linked, but knowing one doesn’t easily reveal the other. Think of it like a lock and key – anyone can use the lock (public key) to secure something, but only someone with the correct key (private key) can open it.

Step-by-Step: Encryption & Decryption

  1. Encryption with the Public Key: Anyone wanting to send you a secret message uses your public key. This scrambles the message into an unreadable format.
    • Example (using OpenSSL):
    openssl enc -aes-256-cbc -in plaintext.txt -out encrypted.enc -pubkey public.pem
  2. Decryption with the Private Key: Only you, possessing your private key, can decrypt the message.
    • Example (using OpenSSL):
    openssl enc -aes-256-cbc -in encrypted.enc -out decrypted.txt -privatekey private.pem
  3. Why it Works: The mathematical functions used ensure that data encrypted with the public key can *only* be decrypted by its corresponding private key, and vice versa.

What Happens if You Try to Use the Wrong Key?

If you attempt to decrypt using the public key instead of the private key, or encrypt with the private key instead of the public key, you will get garbage data. The decryption process won’t produce meaningful output.

Key Differences Summarised

Common Algorithms

Popular asymmetric cryptography algorithms include:

Exit mobile version