Rsa
RSA comes from the names of it's inventors: Rivest, Shamir and Adleman.
public and private key
It provides a public and a private key. The public key is provided to someone who wishes to communicate safely.
The idea is that a message encrypted with the public key can only be decrypted with the private key. So that is why it can be sent to anyone or even published, encrypt all you want, i am the only one who can decrypt it !
algorithm
This is based on two prime numbers : p and q If you know these numbers you can decrypt the message, they should be large and kept secret. But we will use small ones for this example:
This N is known as the modulus, you can see this for example in certificates (see below)
Choose an exponent based on phi, it should be a prime, bigger than 1 and smaller than 3120, and not be a divisor of 3120 (so not 2, 3, 5, but 7 is ok) This is usually a small number, see below. We choose 17
| exponent | |
|---|---|
Calculate d such that exp * d % phi(N) = 1:
The public key :
Where ^ is "to the power of"
The private key
To encrypt a letter 'm' (65) this would be :
| encrypt 'm' | |
|---|---|
so 2790 is the encrypted 'm', only if you know d you can decrypt the message with :
| decrypt with public key 3233 | |
|---|---|
So the number n (3233) is also publicly available.
Note that you never need P and Q again.
For small numbers like these, you could just dissolve 3233 back into p and q, and so calculate d again. But it's just the difficulty to factor large numbers back into those two primes that ensures the safety of the algorithm.
As an example of how large see this RSA example, it's a public key so modules is n, and exponent = e.
In a private key, the private exponent will also be a large number, you can show all components with this command :
| rsa | |
|---|---|
ssh
Note : though ssh uses this scheme for authentication, it does NOT for encryption!!. Whenever the opposite party is authenticated, they both establish an encryption key that is symmetric and that is then used to communicate. Nothing in the outside world ever sees anything of this key.