AP CSP Cybersecurity

Public / Private
Key Lab

Explore how one key can lock a message, while a different matching key unlocks it.

Concept Setup

Two Keys, Two Jobs

Public Key

A public key is meant to be shared. Other people can use it to encrypt a message for the key owner or verify that the owner signed something.

Private Key

A private key stays secret. The owner uses it to decrypt messages sent to them or create a digital signature.

Lab Model

This solo lab gives you a simulated partner so you can practice both sending and receiving without a classmate. The key tokens, ciphertext, and signatures are simplified for learning, but the process is the same.

Lab Part 1A

Send: Encrypt a Message For Your Partner

You need to send a message securely to your partner.

Encrypted for partner
Key Cards
Your Public Key
Your Private Key
Partner Public Key

Your partner's private key is not a tool you get to use. It is your partner's secret.

Plaintext
Encryption Key
Drag a key card here to use it to encrypt the message. You can also click a key, then click here. Use the key that belongs to the person who should be able to read it.
Sent State
Ciphertext will appear here after encryption.
Lab Part 1B

Receive: Decrypt Your Partner's Message

Your partner sent you a secure response. They used your public key to send you a private message. Choose the key that pairs with the public key your partner used.

Decrypted received message
Key Cards
Your Public Key
Your Private Key
Partner Public Key

Your partner encrypted this for you using your public key. Your job is to open it.

Incoming Ciphertext
Decrypt Received Message
The message was locked with your public key. Which matching key opens it?
Decrypted Plaintext
Plaintext will appear here after decryption.
Lab Part 1C

Practice: Encrypt One More Message

Same key pair, new message. Pick the key that lets your partner read it later.

Encrypted second message
Key Cards
Your Public Key
Your Private Key
Partner Public Key

The receiver's public key locks the message for that receiver.

Plaintext
Encryption Key
Use the public key for the person who should be able to decrypt this.
Sent State
Ciphertext will appear here after encryption.
Lab Part 1D

Practice: Decrypt One More Reply

Your partner sent a second secure response. This time, decide faster: which key opens messages sent to you?

Decrypted second reply
Key Cards
Your Public Key
Your Private Key
Partner Public Key

Your public key can be shared. Your private key is kept just for you.

Incoming Ciphertext
Decrypt Received Message
This was locked with your public key. Use the matching private key.
Decrypted Plaintext
Plaintext will appear here after decryption.
Part 1 Debrief

Why Sharing a Public Key Is Safe

Public keys lock messages

When someone uses your public key, they can create a message intended for you. Sharing that public key does not give them the matching private key.

Private keys unlock messages

The private key is the secret part. If it stays protected, only the owner can decrypt messages that were encrypted with the matching public key.

The math used to encrypt with a public key is a one-way operation: it cannot be reversed using that same key. The public key can only lock a message. It cannot undo its own work and decrypt what it just encrypted. Only the mathematically paired private key can run the reverse operation.

Confidentiality means protecting who can read the message. In asymmetric encryption, you usually encrypt with the receiver's public key so only the receiver's private key can decrypt it.

Lab Part 2

Sign a Message, Then Verify It

First, create a valid signature and verify the original message.

Signed message Verified valid signature
Key Cards
Your Public Key
Your Private Key
Partner Public Key

Your partner's private key stays off the table. You can verify their public messages, but you cannot sign as them.

Message To Sign
Sign Message
Use the key that only you have to prove the message came from you.
Signed State
Signature token will appear here.
Verify Signature
Use the public key that matches the signer.
Lab Part 2B

Verify a Message That Changed

The signature was created for the original message. Now test what happens when the message text is altered after signing.

Tamper failed verification
Key Cards
Your Public Key
Your Private Key
Partner Public Key

A public key can verify a signature, but it should reject a changed message.

Tampered Signed Message
Sign and verify the original message first.
Verify Tampered Message
Use the signer public key again. The key is right; the message is the part being tested.
Tampered Copy
Capstone

Verify and Decrypt a Partner Message

Your partner signed a message, then encrypted it for you. First check who sent it, then open it.

Verified partner signature Decrypted partner message
Key Cards
Your Public Key
Your Private Key
Partner Public Key

Verify that your partner is the person who sent this message. Then decrypt the message that was sent to you.

Signed + Encrypted Package
Verify Partner Signature
Which public key proves this package was signed by your partner?
Decryption
Decrypt Partner Message
After verification, use the key that opens messages encrypted for you.
Plaintext message will appear here after verification and decryption.
Wrap Up

Public / Private Key Takeaways

Your Lab Progress

  • -Encrypted a message for a partner
  • -Decrypted a received message
  • -Encrypted a second message for the partner
  • -Decrypted a second received message
  • -Signed a message with your private key
  • -Verified a valid signature with your public key
  • -Observed tampered-message verification fail
  • -Verified a signed partner message
  • -Decrypted a message sent to you

Remember

  • Encrypt with the receiver's public key to protect confidentiality.
  • Decrypt with the receiver's private key because only the receiver should have it.
  • Sign with your private key to attach proof that the message came from you.
  • Verify with the matching public key to check authenticity and detect changes.

Real cryptography uses carefully designed algorithms, trusted libraries, and secure key management. This activity is a simplified model to make the roles of the keys visible.