2.1 Public key, private key and key exchange
Week 2 Day 1 - Ciphers and Public/Private Key
Last Update Unknown
Diffie-Hellman
The Diffie–Hellman key exchange method allows two parties that have no prior knowledge of each other to jointly establish a shared secret key over an insecure channel. This key can then be used to encrypt subsequent communications using a symmetric-key cipher.
An attacker can listen to the values of A and B, but should not be able to determine the secret key.
Diffie-Hellman suffers from a man-in-the-middle attack, where an attacker negotiates for each side, and creates two encryption channels.
RSA and AES Algorithms
RSA
RSA is an asymmetric encryption algorithm which can be used as a cipher to securely transmit messages over the Internet, or as a key-exchange mechanism.
Set-up:
- Select two prime numbers (p,q)
- Calculate n = p x q
- Calculate PHI = (p-1)x(q-1)
To calculate the Public Key:
- Select e so that GCD(e,PHI)=1
- Your Public Key is: (n,e)
To calculate the corresponding Private Key
- Calculate d = e⁻¹ mod PHI
- The private key is: (n,d)
To encrypt message m: c(m) = mᵉ mod n
To decrypt message m: m(c) = cᵈ mod n
AES
AES is a symmetric encryption algorithm, which is lightweight and a lot faster than RSA. It is suitable for bulk encryption work and is used to encrypt data subsequent to the key exchange.
Using public and private keys
Public keys are keys which relate to extremely large prime numbers (as it is difficult to factorise large prime numbers). It is extremely difficult to determine a private key from a public key.
Public key generates two keys: A public key and a private one. These are special in that if one is applied to encrypt, the other can be used to decrypt.
Asymmetric Encryption
The private key is kept secret and the public key is freely available to anyone.
Before A sends it to B:
- The message is hashed to produce a message digest
- The message digest is encrypted with A’s private key, this is now the signature
- The signature is appended to the message
- The message is encrypted using B’s public key
- The encrypted message is sent to B
When B receives A’s message:
- B decrypts the message with B’s private key
- B decrypts the signature with A’s public key to retrieve the original message digest
- The decrypted message is hashed again to reproduce the message digest
- If the decrypted digest equals the reproduced digest, the message has not been tampered with