Example
Imagine Alice wants to send a secure message to Bob. Bob generates a pair of keys: a public key and a private key. He shares his public key with Alice. Alice uses this public key to encrypt her message. When Bob receives it, he uses his private key to decrypt the message. This way, even if someone intercepts the message, they cannot read it without Bob's private key. This example illustrates the fundamental process of public key cryptography.
Sign up to unlock quizzes
Example
One common algorithm used in public key cryptography is RSA, which stands for Rivest-Shamir-Adleman, named after its inventors. RSA works by multiplying two large prime numbers to create a public key. The security lies in the fact that, while it is easy to multiply the two primes together, it is extremely difficult to reverse the process without knowing the original primes. This illustrates the mathematical principles that underpin the security of public key cryptography.
True or False?
Sign up to unlock quizzes
Example
When Alice sends a signed document to Bob, she uses her private key to create a digital signature. Bob can verify this signature using Alice's public key. If the signature matches, it confirms that the document is authentic and has not been tampered with. This process is vital in e-commerce, where the authenticity of transactions must be guaranteed. This example shows how public key cryptography supports integrity and authenticity.
A digital signature is created using the sender's __________ key and verified using the sender's __________ key.
Sign up to unlock quizzes
Code Example
Here is a simple example of generating a key pair using Python's cryptography library:
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa
# Generate private key
private_key = rsa.generate_private_key(
public_exponent=65537,
key_size=2048,
backend=default_backend()
)
# Get public key
public_key = private_key.public_key()
print('Private Key:', private_key)
print('Public Key:', public_key)Your response
Sign up to unlock quizzes
Code Example
Using the public key generated earlier, here is how to encrypt a message:
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.primitives import hashes
message = b'Hello, Bob!'
# Encrypt the message using the public key
ciphertext = public_key.encrypt(
message,
padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA256()),
algorithm=hashes.SHA256(),
label=None
)
)
print('Ciphertext:', ciphertext)Sign up to unlock quizzes
Code Example
Here is how to decrypt the earlier encrypted message using the private key:
# Decrypt the ciphertext using the private key
plaintext = private_key.decrypt(
ciphertext,
padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA256()),
algorithm=hashes.SHA256(),
label=None
)
)
print('Plaintext:', plaintext.decode())True or False?
Sign up to unlock quizzes
You've previewed 6 of 12 pages
Sign up free to unlock the rest of this lesson and start tracking your progress.
6 more pages waiting:
- Page 7
- Page 8
- Page 9
- Page 10
- +2 more...