Does anyone have a Delphi / Pascal example for calling the below OpenSSL functions...
I am specifically interested in:
procedure EVP_CIPHER_CTX_init(a: PEVP_CIPHER_CTX);
function EVP_CIPHER_CTX_cleanup(a: PEVP_CIPHER_CTX): cint;
function EVP_CIPHER_CTX_set_key_length(x: PEVP_CIPHER_CTX; keylen: cint): cint;
function EVP_CIPHER_CTX_ctrl(ctx: PEVP_CIPHER_CTX; type_, arg: cint; ptr: Pointer): cint;
//
function EVP_EncryptInit(ctx: PEVP_CIPHER_CTX; const chipher_: PEVP_CIPHER;const key, iv: PByte): cint;
function EVP_EncryptUpdate(ctx: PEVP_CIPHER_CTX; out_: pcuchar;outlen: pcint; const in_: pcuchar; inlen: cint): cint;
function EVP_EncryptFinal(ctx: PEVP_CIPHER_CTX; out_data: PByte; outlen: pcint): cint;
function EVP_DecryptInit(ctx: PEVP_CIPHER_CTX; chiphir_type: PEVP_CIPHER;const key, iv: PByte): cint;
function EVP_DecryptUpdate(ctx: PEVP_CIPHER_CTX; out_data: PByte;outl: pcint; const in_: PByte; inl: cint): cint;
function EVP_DecryptFinal(ctx: PEVP_CIPHER_CTX; outm: PByte; outlen: pcint): cint;
Thank you!
p.s. I have seen http://www.disi.unige.it/person/FerranteM/delphiopenssl/
Unfortunately that library does not include those functions.
Here are a couple of routines taken straight out of some code I once worked on. They use most of the encryption methods you mention. As mentioned in the comments you really need to get intimate with the OpenSSL docs. I created the stuff below by reading them and going through the C source for the openssl.exe program. (Downloaded from openssl.org).
It's not perfect and makes a couple of assumptions but it does show the basics of using the routines in Delphi.
The original inspiration, as I have mentioned several times before on SO(!), was taken from the stuff at http://www.disi.unige.it/person/FerranteM/delphiopenssl/ that you've already linked to above.
EDIT: Added an import unit at the bottom to supplement what was in the Indy headers when I created these methods. I haven't looked recently so some of this may already be available in Indy.
Decryption:
My extra import unit:
For me the open ssl which is mentioned works however it is not compatible with OpenSSL. A compatible function is needed when you want to decrypt it in java/javascript. To make it work you need to replace the EVP_GetKeyIV routine with the code underneath.
To encrypt a value and base encode it I use the following routine:
To test it you can save the sEncrypted string into a file in.txt. (Do not forget to place a enter at the end) To decrypt using open ssl use:
Open sll command
In the out.txt you will see the origninal value Test