Using Diffie-Hellman secret key to encrypt/decrypt data? My end goal is to encrypt data with AES-128, send it to other process and decrypt it there. While using DH key exchange protocol.

I have used DH to generate a 256 bytes shared secret, but I can't use that key to fit the 128-bit encrypting function. 

I read that the secret needs to be fed through a "Key-based key derivation function" (KBKDF), but as I understand that gives you a hash which then you won't be able to dehash... so how does the other program can decrypt the message? 

Can I just truncate the secret message to 128-bit? (I don't think this is the right solution though).

How would the encryption and decryption of the hashed secret work?

Side note. I am trying to do all this with OpenSSL library in C

Thanks.
I read that the secret needs to be fed through a "Key based key derivation function" (KBKDF), but as I understand that gives you a hash which then you won't be able to dehash... so how does the other program can decrypt the message?


The encryptor sends the DH shared secret through the KDF, which gives him a key, which he uses as (for example) an AES key, and uses that AES key to encrypt his data.

The decryptor sends the same DH shared secret through the KDF, which gives him the same key, which he uses as an AES key, and uses that AES key to decrypt his data.

There's no need to 'invert' the KDF; both sides use it in the forward direction