1. Home
  2. Explore
  3. Computer Science
  4. Public-Key Encryption

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Public-Key Encryption

Public-Key Cryptography

Foundations and core ideas

Public-key cryptography uses a mathematically linked pair of keys: a public key that can be shared and a private key that its owner keeps secret. The key pair supports tasks such as encrypting information for a recipient, establishing a shared secret, and creating digital signatures.

The foundations of public-key cryptography were described in work by Diffie and Hellman in 1976. Their work introduced a way for people to establish a shared secret over a channel that others might be able to observe. RSA, developed by Rivest, Shamir, and Adleman in 1977, became a prominent public-key method.

These methods rely on trapdoor problems:

  • A problem is designed to be difficult to solve without particular secret information.

  • Knowing the secret makes a related operation easy.

  • In cryptography, the secret information is associated with a private key.

For example, multiplying two large prime numbers is straightforward, while finding the original primes from their product is computationally difficult when the primes are sufficiently large.

Public and private keys

Each user, such as Bob or Alice, can have their own key pair.

  • Public key: Shared with others. It can be used, depending on the cryptographic method, to encrypt information for the key owner or verify that owner’s signature.

  • Private key: Kept secret by its owner. It can be used to decrypt information intended for the owner or create signatures associated with the owner.

A crucial distinction is that public-key encryption does not mean that the public key decrypts the message. To send confidential data to Alice, Bob uses Alice’s public key to encrypt it; Alice uses her private key to decrypt it.


Main mathematical problem families

Public-key methods are commonly based on one of three kinds of hard mathematical problems.

Integer factorization

RSA relies on the difficulty of factoring a large composite number into its prime factors. If two large primes, ppp and qqq, are multiplied to form n=pqn = pqn=pq, calculating nnn is easy. Recovering ppp and qqq from nnn is intended to be infeasible with appropriately chosen primes and sufficiently large parameters.

Discrete logarithms

Finite-field discrete-logarithm methods use modular exponentiation. A typical relationship has the form

y≡gx(modp)y \equiv g^x \pmod py≡gx(modp)

where ggg is a generator, ppp is a large prime, and xxx is a secret exponent. Calculating yyy from ggg, xxx, and ppp is straightforward. The intended hard problem is finding xxx when yyy, ggg, and ppp are known.

Methods based on this family include Diffie–Hellman key exchange and ElGamal encryption and signatures. These methods remain important, although their security depends on the specific parameters and implementation.

Elliptic-curve discrete logarithms

Elliptic-curve cryptography (ECC) uses points on a mathematical curve and an operation called point addition. Repeatedly adding a point to itself is easy to perform; recovering how many additions were made from the starting and ending points is intended to be difficult.

ECC can offer strong security with shorter keys than traditional RSA or finite-field methods. For example, ECC commonly uses parameters around 256 bits, whereas RSA keys are typically thousands of bits long. Key sizes are not directly equivalent measures of security, but shorter ECC keys can reduce storage and computation costs.

Quantum-computing risk

A sufficiently capable, fault-tolerant quantum computer could use Shor’s algorithm to solve the factoring and discrete-logarithm problems that underpin RSA, finite-field methods, and conventional ECC. These methods would therefore not retain their expected security against such a computer. Cryptographic systems are consequently developing and adopting post-quantum cryptography, which is based on different mathematical problems.


What public-key cryptography is used for

Public-key methods support three related but distinct purposes: confidentiality, key establishment, and proof of origin.

1. Encrypting data for a recipient

To send confidential information to Alice:

  1. Bob obtains Alice’s authentic public key.

  2. Bob encrypts the information using that public key.

  3. Alice uses her private key to decrypt the result.

This ensures that only the holder of Alice’s private key should be able to decrypt the information, assuming the cryptographic method is secure and the private key has not been compromised.

Public-key operations are relatively computationally expensive compared with symmetric-key encryption. They are therefore generally not used to encrypt large amounts of data directly.

2. Establishing a symmetric key

Public-key cryptography can help Bob and Alice establish or deliver a secret key that they will use for symmetric encryption. A common approach is:

  1. Bob generates a symmetric key for their communication.

  2. Bob protects that key using Alice’s public key, or they establish a shared key through a key-agreement method.

  3. Alice uses her private key, or her corresponding key-agreement secret, to recover or derive the shared key.

  4. Bob and Alice use the symmetric key to encrypt and decrypt their larger data exchange.

Symmetric encryption is much more efficient for bulk data. Public-key techniques are therefore commonly used to establish or protect a symmetric key, while symmetric encryption handles the main message.

3. Creating and verifying a digital signature

A digital signature provides evidence that a message was signed using a particular private key and that the signed content has not changed since it was signed.

A simplified signing and verification process is:

  1. Bob computes a hash of the message.

  2. Bob creates a digital signature using his private key and the hash.

  3. Alice computes a hash of the message she received.

  4. Alice verifies Bob’s signature using Bob’s public key.

  5. The signature verification checks whether the signature corresponds to the message hash and Bob’s public key.

If verification succeeds, Alice gains evidence that the message was signed by the holder of Bob’s private key and that the message matches the signed content. This does not, by itself, prove Bob’s real-world identity: Alice also needs a trustworthy way to associate Bob’s identity with his public key.

A signature is not generally just an encrypted hash. That description can help introduce the idea, but actual signature algorithms use defined signing and verification procedures. Signatures provide authenticity and integrity, not confidentiality; a separately encrypted message is needed to keep content secret.


Public keys, certificates, and key rings

The security of public-key cryptography depends on obtaining the correct public key. An attacker who substitutes a different key could impersonate someone or intercept communications.

Digital certificates

A digital certificate is a digitally signed statement that associates an identity with a public key. A trusted organization, often called a certificate authority, signs the certificate. The recipient can check that signature and assess whether the organization is trusted.

For example:

  1. Bob provides a certificate containing his public key and identity information.

  2. A trusted authority has signed the certificate.

  3. Alice verifies the authority’s signature using the authority’s public key.

  4. If the certificate is valid and trusted, Alice can use the public key in it as Bob’s key.

The certificate is intended to distribute public-key information. Bob’s private key is not included in a public certificate; it must remain secret and be protected separately.

Key rings and repositories

A user may store public keys and certificates in a key ring or retrieve them from a repository. Alice can then select Bob’s verified public key when she needs to communicate with him, rather than requesting it each time.

A key ring may also be used to manage Alice’s own key material, but her private key must be protected against unauthorized access. Storing it alongside public keys does not make it safe automatically; secure storage and access controls are essential.


RSA

RSA is a public-key method based on the difficulty of factoring a large modulus.

Key generation

RSA begins with two large, distinct prime numbers, ppp and qqq. Their product is the modulus:

n=pqn = pqn=pq

The modulus nnn is used in both the public and private keys. Factoring nnn to recover ppp and qqq is intended to be computationally infeasible at appropriate key sizes.

RSA key generation also uses Euler’s totient value for this modulus:

ϕ(n)=(p−1)(q−1)\phi(n) = (p-1)(q-1)ϕ(n)=(p−1)(q−1)

An encryption exponent eee is selected so that it is relatively prime to ϕ(n)\phi(n)ϕ(n):

gcd⁡(e,ϕ(n))=1\gcd(e,\phi(n)) = 1gcd(e,ϕ(n))=1

A private exponent ddd is then chosen as the multiplicative inverse of eee modulo ϕ(n)\phi(n)ϕ(n):

ed≡1(modϕ(n))ed \equiv 1 \pmod{\phi(n)}ed≡1(modϕ(n))

Thus, the public key is (n,e)(n,e)(n,e) and the private key is (n,d)(n,d)(n,d). The primes and other sensitive key-generation material must be kept secret.

Encryption and decryption

For a message represented as an appropriate number mmm, RSA encryption produces a ciphertext ccc:

c≡me(modn)c \equiv m^e \pmod nc≡me(modn)

Decryption uses the private exponent:

m≡cd(modn)m \equiv c^d \pmod nm≡cd(modn)

The notation “modulo nnn” means that the result is the remainder after division by nnn. RSA works because the exponents are constructed so that the private operation reverses the public operation for properly encoded messages.

In real systems, RSA must use secure padding and encoding schemes. Textbook RSA, applied directly to raw message values, is not secure for practical use. RSA is also commonly used in digital signatures through secure signature schemes rather than by simply treating signing as ordinary encryption.

Small illustrative example

Consider the deliberately tiny primes p=3p=3p=3 and q=11q=11q=11. Then

n=3×11=33n = 3 \times 11 = 33n=3×11=33

and

ϕ(n)=(3−1)(11−1)=20\phi(n) = (3-1)(11-1) = 20ϕ(n)=(3−1)(11−1)=20

Choose e=3e=3e=3, which is relatively prime to 202020. The value d=7d=7d=7 works because

3×7≡1(mod20)3 \times 7 \equiv 1 \pmod{20}3×7≡1(mod20)

The public key is (33,3)(33,3)(33,3) and the private key is (33,7)(33,7)(33,7). This example demonstrates the arithmetic only: such tiny values can be factored immediately and are completely insecure.

In practical RSA, the modulus is thousands of bits long. A modulus around 2,000 bits can be formed from two primes around 1,000 bits each, though modern security requirements commonly use larger RSA sizes.


Elliptic-curve cryptography

ECC uses arithmetic on points of an elliptic curve over a finite field. One common curve form is

y2≡x3+ax+b(modp)y^2 \equiv x^3 + ax + b \pmod py2≡x3+ax+b(modp)

where ppp is a prime and aaa and bbb are curve parameters. Working modulo ppp means that coordinate calculations use values in a finite set rather than points on an unrestricted continuous curve.

Elliptic-curve point addition combines points on the curve to produce another point on the curve. The curve parameters and an agreed starting point, called the base point and often written GGG, define the group used for cryptographic operations. The number of points in the group is its order.

Private and public keys

An ECC private key is a secret integer, or scalar, often written kkk. The corresponding public key is the point

P=kGP = kGP=kG

Here, kGkGkG means adding the base point GGG to itself kkk times according to the curve’s point-addition rules. Computing PPP from kkk and GGG is efficient. Recovering kkk from PPP and GGG is the elliptic-curve discrete-logarithm problem and is intended to be computationally infeasible.

The curve parameters, base point, and public key can be public. The private scalar must remain secret.

Common curves and efficiency

Examples of commonly encountered curve families include Curve25519 and secp256k1, which is used in Bitcoin. Curve25519 is based on arithmetic involving the prime

2255−192^{255}-192255−19

ECC can achieve useful security with much shorter keys than RSA, reducing the amount of data and computation needed for many operations. A 256-bit elliptic-curve key is not equivalent in security to a 256-bit RSA key; the two systems rely on different problems and have different security levels. A 160-bit ECC key is now generally considered too small for new security-sensitive systems.

ECC for signatures and key agreement

ECDSA, the Elliptic Curve Digital Signature Algorithm, is an ECC-based signature scheme. The private key is used to sign, and the corresponding public key is used to verify. ECDSA requires a suitable per-signature nonce—a temporary secret value. Reusing or improperly generating that value can expose the private key.

ECDH, Elliptic Curve Diffie–Hellman, is an ECC-based key-agreement method. Its purpose is to let two parties derive a shared secret from their private keys and each other’s public keys. ECDH is not a signature algorithm: signatures and key agreement are different cryptographic tasks.

In a cryptocurrency transaction, for example, a signing method can let a network check that a transaction was authorized by the holder of a corresponding private key. The public key or an identity derived from it can be used in verification, but the private key is never meant to be revealed.


Combining the methods: hybrid encryption

A practical system often combines signatures, symmetric encryption, and public-key cryptography. Pretty Good Privacy (PGP) illustrates this hybrid approach.

Suppose Bob wants to send Alice a confidential message and provide evidence that it came from him:

  1. Hash the message. Bob computes a hash of the message. A hash is a fixed-size digest intended to change if the message changes.

  2. Sign the message. Bob uses his private signing key to create a digital signature associated with the message hash.

  3. Attach the signature. Bob packages the message with the signature. This provides material Alice can use to check the message’s integrity and origin.

  4. Generate a symmetric key. Bob creates a fresh symmetric key for this message.

  5. Encrypt the package. Bob uses the symmetric key to encrypt the message and its signature. This is efficient even for a large message.

  6. Protect the symmetric key for Alice. Bob encrypts the symmetric key using Alice’s public key, or uses an appropriate key-establishment method.

  7. Send both encrypted components. Alice receives the encrypted message package and the protected symmetric key.

  8. Recover the symmetric key. Alice uses her private key to decrypt or derive the symmetric key.

  9. Decrypt and verify. Alice uses the symmetric key to recover the message and signature, computes a fresh hash of the message, and verifies Bob’s signature using Bob’s public key.

If the signature verifies against Alice’s computed hash, Alice has evidence that the message is consistent with the signed content and was signed using the private key corresponding to Bob’s public key. Confidentiality comes from the symmetric encryption; the signature provides authentication and integrity. Trust in the claimed identity still depends on Alice having a reliable association between Bob and his public key.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent