Public Key Encryption

Public key encryption (asymmetric encryption) is a method that uses two mathematically linked keys, a public key anyone can use to encrypt a message and a private key only the receiver holds to decrypt it, letting two parties communicate securely without ever sharing a secret key.

Verified for the 2027 AP Computer Science Principles examLast updated June 2026

What is Public Key Encryption?

Public key encryption is a way to scramble data using a pair of keys instead of one. The public key is shared openly, and anyone can use it to encrypt a message. The private key is kept secret by the receiver, and it's the only thing that can decrypt that message. Because the keys do different jobs, this is also called asymmetric encryption.

Here's the part that makes it click. The big problem with single-key (symmetric) encryption is the chicken-and-egg issue. How do you secretly share the key with someone if you don't already have a secure channel? Public key encryption solves it. Think of it like a mailbox with a mail slot. Anyone can drop a letter in (encrypt with the public key), but only the person with the mailbox key (the private key) can open it and read what's inside. The sender never needs to know the receiver's private key, which is exactly why strangers on the internet, like you and an online store, can exchange sensitive data safely.

Why Public Key Encryption matters in AP Computer Science Principles

Public key encryption lives in Topic 5.6 Safe Computing in Unit 5: Impact of Computing, under learning objective AP Comp Sci P 5.6.B (explain how computing resources can be protected and can be misused). Topic 5.6 covers two sides of one coin. Attackers can intercept data sent over public networks (think rogue access points and keylogging under 5.6.C), and public key encryption is one of the main defenses. It's the technology behind the padlock icon in your browser, working alongside digital certificates and certificate authorities to verify you're actually talking to the real website. On the exam, it connects the privacy risks of 5.6.A (your PII traveling across networks) to the protections of 5.6.B.

How Public Key Encryption connects across the course

Encryption and Symmetric Encryption (Unit 5)

Encryption is the umbrella term for encoding data so unauthorized parties can't read it. Symmetric encryption uses one shared key for both encrypting and decrypting, while public key encryption uses a pair. Public key encryption exists specifically to fix symmetric encryption's weakness, the awkward problem of securely sharing the key in the first place.

Digital Certificates and Certificate Authorities (Unit 5)

Public key encryption has a trust problem. How do you know the public key you grabbed actually belongs to your bank and not an impostor? Digital certificates, issued and verified by certificate authorities, vouch that a public key really belongs to who it claims to. Together they make HTTPS work.

Data Interception on Public Networks (Unit 5)

The CED says data sent over public networks can be intercepted, analyzed, and modified, for example through a rogue access point. Public key encryption is the countermeasure. An attacker can capture your encrypted packets all day, but without the private key the data is unreadable gibberish.

PII and Privacy Risks (Unit 5)

Topic 5.6.A covers how personally identifiable information like financial data, medical info, and biometric data gets collected and stored. Public key encryption is how that PII survives the trip across the internet, which is why your browser uses it before sending payment information to a retailer's server.

Is Public Key Encryption on the AP Computer Science Principles exam?

Public key encryption shows up in multiple-choice questions, since the AP CSP exam has no FRQ on this topic. Expect scenario-based stems rather than bare definitions. A typical question describes a browser sending sensitive payment information to an online retailer and asks which encryption method fits, or describes a user encrypting a confidential message and asks you to name the process. You need to do three things: identify which key does which job (public encrypts, private decrypts), explain why the sender never needs the receiver's private key, and recognize public key encryption as the answer when a scenario involves secure communication between parties who have never met. Watch for distractors that flip the keys or describe symmetric encryption.

Public Key Encryption vs Symmetric Encryption

Symmetric encryption uses one shared secret key for both encrypting and decrypting, so both parties must already have the same key. Public key (asymmetric) encryption uses two different keys, a public one to lock and a private one to unlock. The exam tell is the key count and the sharing problem. If the scenario involves strangers communicating securely without exchanging a secret beforehand, it's public key encryption.

Key things to remember about Public Key Encryption

  • Public key encryption uses two keys: a public key that anyone can use to encrypt a message, and a private key that only the receiver holds and uses to decrypt it.

  • The sender never needs the receiver's private key, which solves the key-sharing problem that symmetric (single-key) encryption can't handle on its own.

  • It falls under Topic 5.6 Safe Computing and learning objective AP Comp Sci P 5.6.B, as a way computing resources and data are protected from unauthorized access.

  • It defends against data interception on public networks; an attacker can capture encrypted traffic but can't read it without the private key.

  • Digital certificates from certificate authorities verify that a public key truly belongs to its claimed owner, which is what makes HTTPS trustworthy.

  • On the exam, scenarios about sending sensitive data (like payment info) to a server you've never communicated with before point to public key encryption.

Frequently asked questions about Public Key Encryption

What is public key encryption in AP CSP?

It's an encryption method that uses a pair of keys, a public key anyone can use to encrypt a message and a private key only the receiver holds to decrypt it. It appears in Topic 5.6 Safe Computing under learning objective AP Comp Sci P 5.6.B.

Is the public key used to decrypt messages?

No. The public key only encrypts. Only the matching private key can decrypt the message, which is the whole point. Anyone can lock a message for you, but only you can unlock it.

What's the difference between public key encryption and symmetric encryption?

Symmetric encryption uses one shared key for both encrypting and decrypting, so both parties need the same secret in advance. Public key encryption uses two different keys, so a sender can encrypt without ever knowing the receiver's secret. That's why it works between strangers on the internet.

Why is public key encryption called asymmetric?

Because the two keys do different jobs and aren't interchangeable. The public key encrypts and the private key decrypts, unlike symmetric encryption where one key does both.

Do I need to know the math behind public key encryption for the AP exam?

No. AP CSP only expects you to understand the concept: which key does what, why the sender doesn't need the private key, and when a scenario calls for it (like a browser sending payment info to a server). The underlying math is beyond the course.