Asymmetric (Public-Key) Encryption
In asymmetric encryption each user has a key pair: a public key, shared openly, and a private key, kept secret. Data encrypted with the public key can be decrypted only with the matching private key, so no secret key needs to be shared in advance. It is much slower than symmetric encryption, so it is used for key exchange and signatures, while the bulk data is encrypted symmetrically (a hybrid system).
RSA
RSA (Rivest, Shamir, Adleman, 1977) is based on the difficulty of factoring a large number into primes. Steps: choose two large primes p and q; compute n = p × q and φ(n) = (p − 1)(q − 1); choose e coprime to φ(n); compute d so that e × d ≡ 1 (mod φ(n)). The public key is (e, n) and the private key is (d, n). Encryption: c = mᵉ mod n. Decryption: m = cᵈ mod n. Real keys are 2048 bits or more.
Diffie-Hellman Key Exchange
Diffie-Hellman (1976) lets two parties create a shared secret over an open channel. They agree on a public prime p and base g. Alice picks a secret a and sends A = gᵃ mod p; Bob picks b and sends B = gᵇ mod p. Each computes the secret: Alice Bᵃ mod p, Bob Aᵇ mod p, and both equal gᵃᵇ mod p. An eavesdropper sees p, g, A and B but cannot easily find a or b (the discrete logarithm problem). Plain Diffie-Hellman is open to a man-in-the-middle attack unless the parties are authenticated.
Hash Functions and Digital Signatures
A cryptographic hash function (SHA-256, SHA-3) maps any input to a fixed-size digest. It must be one-way, give a different digest for any change, and be collision resistant. MD5 and SHA-1 are broken for collisions and should not be used for security. Hashes check integrity and store passwords (with a salt). A digital signature proves who sent a message and that it was not changed: the sender hashes the message and encrypts the digest with the private key; the receiver decrypts it with the public key and compares it with a fresh hash. It gives authentication, integrity and non-repudiation.
Applications and Cryptanalysis
Applications: HTTPS/TLS, secure e-mail, VPNs, disk and file encryption, password storage, digital certificates, software signing, UPI and card payments, and blockchain. Cryptanalysis is the study of breaking ciphers without the key. Attack types by knowledge are ciphertext-only, known-plaintext, chosen-plaintext and chosen-ciphertext. Methods include brute force, frequency analysis (for classical ciphers), side-channel attacks (timing or power) and mathematical attacks. Strength rests on key length and good design.
Definition: Digital signature. A value created by hashing a message and encrypting the hash with the sender's private key, which anyone can verify with the public key to confirm the sender and that the message is unchanged.
Table 1.5: Symmetric and asymmetric encryption
| Feature | Symmetric | Asymmetric |
|---|---|---|
| Keys | One shared secret key | Public and private key pair |
| Speed | Fast | Slow |
| Key distribution | Difficult | Easy (public key is open) |
| Examples | AES, 3DES | RSA, ECC, Diffie-Hellman |
| Use | Bulk data | Key exchange, signatures |
Example 1.5: RSA and Diffie-Hellman with small numbers
Problem: (a) RSA: p = 61, q = 53, e = 17, message m = 65. Find n, φ(n), d, the ciphertext and the decryption. (b) Diffie-Hellman: p = 23, g = 5, a = 6, b = 15. Find A, B and the shared secret.
Solution (a):
- n = 61 × 53 = 3233 and φ(n) = 60 × 52 = 3120.
- d is the inverse of 17 modulo 3120, which is d = 2753 (17 × 2753 = 46801 = 15 × 3120 + 1).
- c = 65¹⁷ mod 3233 = 2790; decryption 2790²⁷⁵³ mod 3233 = 65.
Solution (b):
- A = 5⁶ mod 23 = 8 and B = 5¹⁵ mod 23 = 19.
- Alice: 19⁶ mod 23 = 2. Bob: 8¹⁵ mod 23 = 2.
Result: RSA recovers the message 65 from ciphertext 2790, and both Diffie-Hellman parties obtain the same secret 2. (Real systems use numbers hundreds of digits long.)
p, q, e, m = 61, 53, 17, 65
n, phi = p * q, (p - 1) * (q - 1)
d = pow(e, -1, phi)
c = pow(m, e, n)
print("n:", n, "phi:", phi, "d:", d)
print("cipher:", c, "| decrypted:", pow(c, d, n))
P, g, a, b = 23, 5, 6, 15
A, B = pow(g, a, P), pow(g, b, P)
print("A:", A, "B:", B)
print("secrets:", pow(B, a, P), pow(A, b, P))
Output
n: 3233 phi: 3120 d: 2753
cipher: 2790 | decrypted: 65
A: 8 B: 19
secrets: 2 2
Common mistakes
- Using MD5 or SHA-1 where collision resistance matters.
- Storing passwords as plain hashes without a salt.
- Using Diffie-Hellman without authenticating the other party.
- Believing that asymmetric encryption should be used for all data.
Key takeaways
- RSA: n = pq; c = m^e mod n; m = c^d mod n; security from factoring.
- Diffie-Hellman: shared secret g^(ab) mod p over an open channel.
- Hash: one-way, fixed length, collision resistant; sign the hash.
- Cryptanalysis: brute force, frequency analysis, side channel.
Practice questions
- Which keys does a digital signature use?
- What problem makes RSA secure?
- What is a hybrid cryptosystem?
Answers to the practice questions
- It is made with the sender's private key and verified with the public key.
- The difficulty of factoring a large number into its prime factors.
- Using asymmetric encryption to exchange a key and symmetric encryption for the bulk data.
Sources
- Official BCA syllabus Computer Security, course code 25BCA406DS02, Unit I
