Professional Documents
Culture Documents
It's often required that a message be encrypted between two parties for secure communication. There are plenty of algorithms out there for encryption that are very secure, but their weakness lies in transporting the encryption key. The Diffie-Hellman key exchange protocol allows people to exchange keys in a manner that does not allow an eavesdropper to calculate the key in a fast manner. This code demonstrates the use of this type of key exchange.
DH->CreateKeys(g,n); DH->CreateSenderInterKey(SInterim); //The sender now sends (n, g, and SInterim) to the receiving application //This can be done unencrypted because they are public keys //Now we wait until the reciever send us their interim key lets say RInterim DH->CreateSenderEncryptionKey(key,RInterim); //The shared encryption key is now the value of 'key'
//Wait for the values of (n,g, and SInterim) to be sent here DH->CreateRecipientInterKey(RInterim); //Now send the RInterim key to the sender application DH->CreateRecipientEncryptionKey(key,SInterim); //The shared encryption key is now the value of 'key'
Extra Functions
There are some private member functions of the CDiffieHellman class that you may find useful, and please feel free to use them.
The GeneratePrime() function generates a large prime number. The MillerRabin and IsItPrime functions can be used in conjunction to test primality. The XtoYmodN is a function to raise x to the power of y in modulus n. Even though it sounds impossible for a computer to work out, say 150 million to the power of 150 million, this can be done in modulus n by using the power chaining method.
Further Help
Should you require any additional help, please do not hesitate to contact me. I would be interested in hearing your comments, suggestions and any questions.
License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)