# cryptography

• April 15th, 2009, 10:35 AM
sheena
cryptography
What steps are required to integrate AES with Diffie Hellman???
• April 21st, 2009, 05:48 PM
zszafran
I'm not positive how exactly one would integrate one into the other, but I do know they can be used side-by-side fairly easily.

I'm a little bit rusty in regards to cryptography, but I think I'll be able to answer this question for you.

The Diffie-Hellman Key Exchange is a way for two parties to generate a common secret key without actually exchanging the key between themselves. The key that is generated could be considered to be something along the line of a password. When I work with encryption algorithms I like to have a piece of programming code to use as a visual and reference. This is something that I've had bookmarked in my del.icio.us in reference to Diffie-Hellman and the Ruby scripting language:

http://labs.mudynamics.com/2007/05/0...llman-in-ruby/

Ok, so based off that Ruby code, Alice and Bob both have a shared key which only they know. Now what can be done is to use this secret key/password as the key for encrypting and decrypting strings with a simple AES function. Again here is some simple Ruby code for some basic Encrypt and Decrypt AES functions using the OpenSSL library:

http://snippets.dzone.com/posts/show/4975

With the above Ruby examples, it would be possible to implement something along the lines of:

Code:

```# Create diffie-hellman object alice = DH.new(53, 5, 23) bob  = DH.new(53, 5, 15) # Generate public keys alice.generate bob.generate # Exchange public keys and generate secret keys alice_s = alice.secret(bob.e) bob_s  = bob.secret(alice.e) # Alice encrypts a message and sends it to Bob over a socket safe_payload = encrypt(alice_s,"Hello world") # Bob receives the encrypted string and decrypts it into a readable message message = decrypt(bob_s,safe_payload) # Print the message print "Message from Alice: #{message}"```
This isn't the best way to go about securing communications, but it does provide a pretty good idea of how DH and AES could be used together. If you are interested in secure communications, you may want to look into the OpenSSL libraries. They provide easy access to a Secure Socket Layer (SSL) which already had Diffie-Hellman and AES integrated.

I hope this is the answer you were looking for. It's pretty early in the morning and it's been a while since I took any cryptography classes or programmed anything in regards to secure communications, so there is a chance that I may be incorrect or my examples may not work.

-Zach