This is the openssl command line that I am using To encrypt: openssl enc -aes-256-cbc -K 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F -iv 00112233445566778899AABBCCDDEEFF -e -in input.txt -out output.enc
To Decrypt: openssl enc -aes-256-cbc -K 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F -iv 00112233445566778899AABBCCDDEEFF -d -in output.enc -out decrypt.txt My code is simple: void TestEncrypt() { unsigned char aes_key[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F }; unsigned char aes_iv[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; AES_KEY key; string sInput; cout << " enter string (size < 128) : "; cin >> sInput; cout << "input is " << sInput << endl; int inlen = sInput.size(); unsigned char pIV[16]; unsigned char pIn[128]; unsigned char pOut[128]; memset(pOut, 0, 128); memset(pIn, 0, 128); memcpy(pIn, sInput.c_str(), inlen); AES_set_encrypt_key(aes_key, 256, &key); //AES_ecb_encrypt(input, pOut, &key, AES_ENCRYPT); memcpy(pIV, aes_iv, 16); AES_cbc_encrypt(pIn, pOut, inlen, &key, pIV, AES_ENCRYPT); cout << "encrypted output is: "; for (unsigned int i = 0; i < 128; ++i) { cout << hex << showbase << pOut[i]; } cout << endl; AES_set_decrypt_key(aes_key, 256, &key); //AES_ecb_encrypt(pOut, pIn, &key, AES_DECRYPT); memcpy(pIV, aes_iv, 16); memset(pIn, 0, 128); AES_cbc_encrypt(pOut, pIn, inlen, &key, pIV, AES_DECRYPT); cout << "decrypted output is: "; for (unsigned int i = 0; i < 128; ++i) { cout << hex << showbase << pIn[i]; } cout << endl; cout << "done testing" << endl; } On Thu, Sep 3, 2009 at 2:07 PM, Hazel John<hazeljj...@gmail.com> wrote: > I am specifying the key and IV and using the same hex based string for both. > > On Thu, Sep 3, 2009 at 2:02 PM, Victor > Duchovni<victor.ducho...@morganstanley.com> wrote: >> On Thu, Sep 03, 2009 at 01:51:10PM -0500, Hazel John wrote: >> >>> Hi, >>> I need to encrypt simple strings to readable strings using the openssl >>> command line (opessl enc with the -a option to return readable >>> strings) and decrypt this in my code (c++/linux). I tried both the low >>> level aes and evp functions and couldn't get the results to match. Is >>> there a default padding used by the openssl command line? I tried >>> using the cbc alogorithm and padded it with the null char and thought >>> I can encrypt/decrypt correctly using openssl command line or my code, >>> I cannot get the encrypted output to match. I am using BIO to base64 >>> encode/decode in my program and that part works well. I am trying to >>> match the encrypted output from my program to the encrypted output >>> using the same cipher with openssl command line and cannot get a >>> match. >> >> Are you using the same password-based key derivation function with the >> same "salt" to derive the encryption key and IV? The "magic" string >> and salt are prepended to the output of "openssl enc". >> >> -- >> Viktor. >> ______________________________________________________________________ >> OpenSSL Project http://www.openssl.org >> User Support Mailing List openssl-us...@openssl.org >> Automated List Manager majord...@openssl.org >> > ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org