Topic 5.4 · Unit 5: Securing Applications and Data · 35 minute session

5.4 Asymmetric Cryptography

Asymmetric encryption lets people communicate securely without prearranging a shared secret key. Each receiver generates a key pair: a public key published for anyone and a private key stored securely. To send securely, encrypt with the receiver's public key; only the receiver's private key decrypts it. An n-bit key has a keyspace of 2^n and needs 2^(n-1) guesses on average. Longer keys are more secure but slower, and lengths compare only within one algorithm. RSA and elliptic curve cryptography (ECC) are common.

Big idea Anyone can lock the box with your public key. Only your private key opens it, so the private key is the whole secret.

Course and exam description (CED) codes covered: 5.4.A.15.4.A.25.4.A.35.4.A.45.4.B.15.4.B.25.4.B.35.4.B.45.4.B.55.4.C.15.4.C.25.4.C.3

Last reviewed against the CED:

By the end of this session you can

  • 5.4.A Determine the appropriate asymmetric key to use when sending or receiving encrypted data.
  • 5.4.B Explain why the length of a key impacts the security of encrypted data.
  • 5.4.C Apply asymmetric encryption algorithms to encrypt and decrypt data.

Already know this? Jump to the checkpoint.

1. Which key to use (5.4.A)

Asymmetric encryption lets users communicate securely without prearranging a shared secret key 5.4.A.1. Every entity that will receive data first generates a key pair: two binary strings of equal length, generated at the same time by a mathematical process. One is the public key, the other the private key. The keys are mathematical inverses: either one can encrypt, but only the other key in the pair can decrypt 5.4.A.2.

The receiver must store the private key securely. If it is exposed, shared, stolen, corrupted or compromised, the key pair must be deleted and a new pair generated, because the security of the algorithm rests on the private key. The public key is published for anyone to view and use 5.4.A.3.

Sana encrypts plaintext with Leo's public key; the ciphertext travels to Leo, who decrypts it with Leo's private key to get the plaintext back.
Figure 1. To send to Leo, Sana encrypts with Leo's public key. Only Leo's private key decrypts.

To send information securely, the sender encrypts with the receiver’s public key. Only the receiver, who has the private key, can decrypt and read it 5.4.A.4.

You want to Use
Send a confidential file to Leo Leo’s public key
Read a confidential file sent to you Your own private key
Let anyone send you confidential files Publish your public key
Respond after your private key is stolen Delete the key pair and generate a new one

2. Why key length matters (5.4.B)

Longer keys give larger keyspaces. An n-bit key has a keyspace of 2n 5.4.B.1. Guessing randomly, an adversary finds the right key in 2n/2 = 2n-1 guesses on average 5.4.B.2.

Key length Keyspace Average guesses
8 bits 28 = 256 27 = 128
9 bits 29 = 512 28 = 256
16 bits 216 = 65,536 215 = 32,768

Each extra bit doubles the keyspace. Longer keys are more secure but take more time to encrypt and decrypt 5.4.B.3. Computing power keeps improving, so key-length recommendations for symmetric and asymmetric algorithms are raised periodically 5.4.B.4. Key lengths can be compared only for the same algorithm: a longer AES key beats a shorter AES key, and a longer RSA key beats a shorter RSA key, but an RSA key and an AES key cannot be compared by length 5.4.B.5.

3. Applying asymmetric encryption (5.4.C)

Common asymmetric algorithms are RSA (named after its inventors, Rivest, Shamir and Adleman) and elliptic curve cryptography (ECC). They are used in many applications, including digital signatures and digital certificates 5.4.C.1. As with symmetric encryption, you can use the command line (OpenSSL), specialized software such as the open source RSA Encryption Tool, or web-based tools 5.4.C.2. With OpenSSL 5.4.C.3 (PEM, privacy-enhanced mail, is the text format the key files use):

Step Command
Generate a 2048-bit RSA key pair into rsa.pem openssl genrsa -out rsa.pem
Extract the public key into public.pem openssl rsa -pubout -in rsa.pem -outform PEM -out public.pem
Encrypt a file with the public key openssl pkeyutl -encrypt -pubin -inkey public.pem -in memo.txt -out memo.enc
Decrypt with the private key openssl pkeyutl -decrypt -inkey rsa.pem -in memo.enc -out memo.txt

Pick the right key for each step with the drop-down menus, then run a real key pair in your browser.

Lock it in: memory hooks

One picture per idea. If you remember the hook, you can rebuild the details.

  • Which keyLock with their public key; they unlock with their private key.
  • Key lengthAdd one bit, double the keyspace.
  • Average guessesHalf the keyspace: 2^n / 2 = 2^(n-1).

Common misconceptions

  • "You encrypt with your own private key to send a secret message."

    Not quite. To keep a message confidential, encrypt with the receiver's public key. Only the receiver's private key can then decrypt it.

  • "A 2048-bit RSA key is safer than a 256-bit AES key because the number is bigger."

    Not quite. Key-length comparison is only valid for the same algorithm. RSA and AES keys cannot be compared directly.

  • "If a private key leaks, just keep it secret from now on."

    Not quite. If the private key is exposed, shared, stolen, corrupted or compromised, delete the key pair and generate a new one.

Simulation · Asymmetric encryption [5.4.A.2, 5.4.A.4, 5.4.B.1, 5.4.C.3]

Key pair lab: public key locks, private key unlocks

Two security engineers at a wind farm company, Sana and Leo, have never met and share no secret. Each generates a key pair and publishes only the public key.

Which key?

  1. Sana sends Leo a confidential design file. Which key does she encrypt it with?

    Show the answer

    Leo's public key. To send securely, the sender uses the receiver's public key. Only Leo's private key can decrypt it.

  2. Leo receives the encrypted file. Which key decrypts it?

    Show the answer

    Leo's private key. The receiver decrypts with their own private key, the partner of the public key used to encrypt.

  3. Leo replies with an encrypted message for Sana. Which key does he encrypt it with?

    Show the answer

    Sana's public key. Now Sana is the receiver, so Leo uses Sana's public key.

  4. Leo's laptop, which stores rsa.pem, is stolen. Which key is now compromised, so Leo must delete his key pair and generate a new one?

    Show the answer

    Leo's private key. The security of asymmetric encryption rests on the private key. If it is exposed or stolen, the key pair must be deleted and a new pair generated.

The same steps in OpenSSL

leo@laptop: ~ (receiver)
# 1. Leo generates a 2048-bit RSA key pair
$ openssl genrsa -out rsa.pem
# 2. Leo extracts the public key and publishes public.pem
$ openssl rsa -pubout -in rsa.pem -outform PEM -out public.pem
# 3. Sana encrypts with Leo's public key
$ openssl pkeyutl -encrypt -pubin -inkey public.pem -in design.txt -out design.enc
# 4. Leo decrypts with his private key (in rsa.pem)
$ openssl pkeyutl -decrypt -inkey rsa.pem -in design.enc -out design.txt

Key length and keyspace

An n-bit key has a keyspace of 2n. Random guessing finds the key in 2n/2 = 2n-1 guesses on average. AES 256-bit beats AES 128-bit and RSA 4096-bit beats RSA 2048-bit, but an AES key and an RSA key cannot be compared by length.

Exam traps

  • Either key in a pair can encrypt, but only the other key in that pair can decrypt.
  • The two keys are binary strings of equal length, generated at the same time, and are mathematical inverses.
  • Key-length recommendations go up over time because computers keep getting faster at guessing.
  • openssl genrsa makes the key pair (rsa.pem holds the private key); openssl rsa -pubout extracts the public key.

By the numbers

Say each list out loud, then tap to check.

2 keys in a pair Say them, then tap
Keyspace of an n-bit key Say them, then tap
  • 2^n possible keys
  • on average 2^(n-1) guesses to find it
2 common asymmetric algorithms Say them, then tap
4 OpenSSL steps Say them, then tap
  • genrsa (make the pair)
  • rsa -pubout (extract public key)
  • pkeyutl -encrypt -pubin
  • pkeyutl -decrypt

In 30 seconds

  1. Asymmetric encryption needs no prearranged shared secret.
  2. Each receiver makes a key pair. Either key can encrypt; only its partner decrypts.
  3. Protect the private key; if it is compromised, delete the pair and make a new one. Publish the public key.
  4. Send: encrypt with the receiver's public key. Receive: decrypt with your private key.
  5. Longer keys mean larger keyspaces (2^n) but slower encryption; compare lengths within the same algorithm only.
  6. RSA and ECC are common; asymmetric algorithms are used in digital signatures and digital certificates.

Cover this list, say the points out loud, then take the checkpoint without scrolling back up.

Checkpoint · 9 questions

Checkpoint: Asymmetric Cryptography

Pick an answer to mark it. Every answer is explained, and you can try any question again. Your saved score counts first tries only, and stays in this browser.

  1. Ravi needs to send a confidential contract to Mei. They have never shared a secret key. Both have published public keys.
    1 Which key should Ravi use to encrypt the file? 5.4.A.4
    Show answer

    Answer: D. To send information securely, the sender uses the receiver's public key. Only the receiver, who has the private key, can decrypt it.

  2. 2 Mei receives a file encrypted with her public key. Which key decrypts it? 5.4.A.4, 5.4.A.2
    Show answer

    Answer: C. Either key in a pair can encrypt, but only the other key in the pair can decrypt. Data encrypted with Mei's public key need Mei's private key.

  3. An engineer realizes her private key file was accidentally uploaded to a public code repository last week.
    3 Which of the following should the engineer do? 5.4.A.3
    Show answer

    Answer: A. If the private key is exposed, shared, stolen, corrupted or compromised, the key pair must be deleted and a new key pair generated.

  4. 4 Which of the following is the main advantage of asymmetric encryption over symmetric encryption? 5.4.A.1
    Show answer

    Answer: D. Asymmetric encryption allows users to communicate securely without prearranging a shared secret key.

  5. 5 On average, how many guesses would an adversary need to find a randomly chosen 12-bit key? 5.4.B.1, 5.4.B.2
    Show answer

    Answer: B. A 12-bit key has a keyspace of 2^12 = 4,096. Random guessing finds it in 2^12 / 2 = 2^11 = 2,048 guesses on average.

  6. A security team lists four keys.
    Keys
    KeyAlgorithmLength
    K1AES256 bits
    K2RSA2048 bits
    K3RSA4096 bits
    K4ECC384 bits
    6 Which conclusion is valid? 5.4.B.5
    Show answer

    Answer: A. Key-length comparison is only valid for the same algorithm. K3 (RSA 4096) is more secure than K2 (RSA 2048). AES and RSA keys cannot be compared directly.

  7. A government guide once recommended a minimum RSA key length of 1024 bits. A later edition raised the minimum to 2048 bits.
    7 Which of the following best explains why the recommendation increased? 5.4.B.3, 5.4.B.4
    Show answer

    Answer: A. Processing power and efficiency keep improving, so key-length recommendations are periodically increased to account for faster guessing.

  8. A receiver has just run openssl genrsa -out rsa.pem.
    8 Which command should the receiver run next so that a sender can encrypt files for them? 5.4.C.3
    Show answer

    Answer: C. After generating the pair with openssl genrsa, the receiver extracts the public key into public.pem to publish it.

  9. 9 Which pair lists two common asymmetric encryption algorithms? 5.4.C.1
    Show answer

    Answer: B. Common asymmetric algorithms include RSA and ECC. AES is symmetric; SHA-256 and MD5 are hash functions.

Key terms: flip the cards

Read the term, say the definition out loud, then flip to check. Struggling a little to remember is what makes it stick.

  • Key pairtap to flip

    Two binary keys of equal length, generated together, that are mathematical inverses: what one encrypts, only the other decrypts.

    Example and CED codes
  • Public keytap to flip

    The key in a pair that is published for anyone to use; senders encrypt with the receiver's public key.

    Example and CED codes
  • Private keytap to flip

    The key in a pair that the owner stores securely and uses to decrypt; if compromised, the key pair must be deleted and replaced.

    Example and CED codes
  • Keyspacetap to flip

    The number of possible keys an encryption algorithm can use; an n-bit key has a keyspace of 2^n.

    Example and CED codes
  • RSAtap to flip

    A common asymmetric encryption algorithm, also used in digital signatures and digital certificates.

    Example and CED codes
  • Elliptic curve cryptography (ECC)tap to flip

    A common family of asymmetric encryption algorithms.

    Example and CED codes
  • Asymmetric encryptiontap to flip

    Encryption that uses two different keys, one to encrypt and the other to decrypt.

    Example and CED codes
  • OpenSSLtap to flip

    A command line tool for encrypting and decrypting with symmetric (openssl enc) and asymmetric (openssl genrsa, pkeyutl) algorithms.

    Example and CED codes

Questions students ask

Which key do you use to send an encrypted message?

The receiver's public key. Only the matching private key, which the receiver keeps secret, can decrypt the message.

How many guesses does it take to find a 10-bit key?

The keyspace is 2^10 = 1,024 keys, so random guessing finds it in 2^9 = 512 guesses on average.

Why are key-length recommendations increased?

Computing power and efficiency keep improving, so software can guess keys faster. Recommendations for symmetric and asymmetric keys are raised periodically to keep up.

Was this page helpful?

Please do not include personal details. To get a reply, email [email protected].

Contents
↑ Top

Enlarged view of the selected figure