This project implements Diffie Hellman algorithm and AES algorithm. What this app does is that it creates two users Alice and Bob. Those two users then generate a unique key for themselves which are known as a & b. After this, they are to agree on two public keys p & q. In this documentation, I will be explaining everything in detail starting off from generating the keys up until printing the messages on the screen
Diffie Hellman algorithm:
The Diffie-Hellman algorithm is being used to establish a shared secret that can be
used for secret communications while exchanging data over a public network using
the elliptic curve to generate points and get the secret key using the parameters.
Parameters: G: is a very huge prime number which is practically crackable. If it was a small number, it would have no meaning because it would be so easy to be cracked. P: It is a primitive root modulo of G.*
- Modulo operation is an operation where the result is the remainder of the division operation performed with two given integers as operands. A: Alice’s private key B: Bob’s private key.
AES algorithm: The AES Encryption algorithm (also known as the Rijndael algorithm) is a symmetric block cipher algorithm with a block/chunk size of 128 bits. It converts these individual blocks using keys of 128, 192, and 256 bits. Once it encrypts these blocks, it joins them together to form the ciphertext
Firstly, two accounts are created for the users. Technically, we have a class for creating users calles USER. We basically call this class two times as we want to create to users.
When we create an instance of this class, the constructor takes the users name and saves it into a variable this.name because we will need to have the name as we will need it to keep track from who we got the message to display his/ her name before the message. After creating an instance, we have to initialize some variables, Private key and IV. Private key is a method whose return type is Biginteger. It generates a random number and then initialize private key to be them the non-sharable key. IV is a byte array that we need it for AES algorithm. It is basically an initialization vector that is used to ensure that the same value encrypted multiple times, even with the same secret key, will not always result in the same encrypted value. This is an added security layer.
After initializing the fields, we call a method called Generate_Key() . what this method does is that it calculates the modulo operation and then initializes the first key calculated from the first user.
We call this function for as many users as there are, so that it calculates the keys for the users. This calculation is the first round. First round:
After Generating the public keys, we exchange the keys between the users. Exchange_Keys(Biginteger GeneratedPublicKey , byte[] IV) This method take the generated keys which are permitted to be exchanged over the network and them calculate the second round. Second round:
Now everything is all set. Keys are exchanged.
For AES, it is the typical algorithm. The only thing I add to it is
The final keys are not consistent in bits and the size of them does not work for AES algorithm and that what happened to me. As AES works with { 128-bit, 192-bit, 256- bit} keys, I used that method that makes the key consistent in bits 32 byte * 8 = 256 bits. This has a salt array filed, it is made up of numbers added to the key before its hashing. it helps creating a unique key.
IDisposable is an interface that contains a single method, Dispose(), for releasing unmanaged resources, like files, streams, database connections and so on.