I'm learning Linux, and currently SSH. But there are details that I don't really understand.

  1. I've seen and understood how Diffie-Hellman key exchanges work from a mathematical point of view, but what I would like to understand is the symmetric key that is generated for further communications. Everything starts with a large prime number g (generator) and n, that we use combine in some ways using discrete logarithms with a private number to generate the public key which is only used for encryption. This key is a number, so how can a number encrypt a message?

  2. Even the symmetrical key obtained is also a number, that will be used for encryption and decryption. Suppose the calculated symmetrical number obtained is 16, how can 16 encrypt a message Good morning that I send to someone and then the same number 16 decrypts the message at the other side?

  3. I've also read that after a key exchange algorithm, AES symmetrical algorithm can be used for further communication. So is AES the symmetrical key generated by Diffie-Hellman key exchange? Is AES a number obtained after calculation using discrete logarithm?

  4. I've also read that RSA can be combined with Diffie-Hellman to enhance security to avoid a MitM attack. So what does RSA really add to the existent key exchange algorithm?

  5. After executing ssh-keygen -t rsa, a key pair has been generated, but when I open them in a text editor, I don't see nothing like prime numbers. It's a different format.

Now I'm really confused about how all this math is related to encrypting data exchanged between 2 computers.

1 Answer 1


This key is a number,so how can a number encrypt a message?

A number is represented as a sequence of bits - this is the key.

is AES a number obtained after calculation using discret logarithm?

AES is an encryption algorithm - see wikipedia:AES. The algorithm uses a key (sequence of bits, see last point) to encrypt some payload and the same payload is used for decryption. Think of something like XOR where the same "key" can be used to "encrypt" some message and "decrypt" it again - only much better than XOR.

... so what does RSA really add to the existent key exchange algorithm?

RSA in the context of SSH adds nothing to the key exchange algorithm itself. But it is used for authentication so that the client can be sure that it does the key exchange with the expected server and not with some man (attacker) in the middle (MITM).

After doing ssh-keygen -t rsa command,a key pair has been generated,but when i open them in a text editor,i don't see nothing like prime numbers,it's a different format.

Again, a number is a sequence of bits. Such a sequence can be encoded in a variety of ways, like as a decimal number, as some hexadecimal number, as a sequence of 1 and 0 and much more. What you see there is a specific encoding of these numbers and also some additional packing information.

Now i've got reall confusion about how all thoses maths are related to encrypt real data exchanged between 2 computers like,messages,photos,videos,etc.

It looks like you are confused because you think as numbers only as something written down as sequence of digits between 0 and 9. But this is just one specific encoding of how numbers can be represented. For the computer everything is just a sequence of bits - everything else (digits, characters, images ...) is just what a specific sequence of bits means for the human.

  • Thank you very much for your answer.I've read that AES is used to encrypt and decrypt,so what is the relashionship between AES which is symetrical algorithms and the symetrical key generated by the Diffie-Helman key exchange? Apr 20, 2019 at 16:11
  • @ChristianLisangola: the relationship is that a symmetrical encryption needs a key known to both sides - and guess what DH provides. Apr 20, 2019 at 16:30
  • I've watched this video : youtube.com/watch?v=Yjrfm_oRO0w&t=196s which explains the concept.The goal of Diffie-Helman key exchange is to use asymmetrical encryption to generate a symmetrical key for communcation.What i want to know is the relashionship that exists between that symmetrical key with AES which also a symmetrical algorithm.In fact,i'm new to all this Apr 21, 2019 at 17:02
  • @ChristianLisangola: I'm not really sure where your problem is. DH is used to create a symmetric key. AES needs a symmetric key for encryption. Thus, DH creates what is needed by AES so that the data can be encrypted and decrypted. And this exactly is the relationship between these two. Apr 21, 2019 at 17:12
  • Thank you very much,this now makes sens to me Apr 22, 2019 at 11:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .