Install add-on in OpenSSL for AES_ecb_encrypt

I am decrypting some java-crypted text with OpenSSL. Reading this post I wrote the following code.

unsigned int i = 0; printf("Out array - Before\n"); for(i = 0; i < sizeof(out); i++) { if(i % 32 == 0) printf("\n"); printf("%02X", out[i]); } printf("\n"); AES_set_decrypt_key((const unsigned char *)a.at(3).c_str(), 128, &aesKey_); for(i = 0; i < sizeof(bytes); i += AES_BLOCK_SIZE) { std::cout << "Decrypting at " << i << " of " << sizeof(bytes) << "\n"; AES_ecb_encrypt(bytes + i, out + i, &aesKey_, AES_DECRYPT); } std::cout << "HEX : " << a.at(2).c_str() << "\n" << "Decrypting : " << bytes << "\n" << "With Key : " << a.at(3).c_str() << "\n" << "Becomes : " << out << "\n"; printf("Out array - AFTER\n"); for(i = 0; i < sizeof(out); i++) { if(i % 32 == 0) printf("\n"); printf("%02X", out[i]); } printf("\n"); 

The decryption of the data seems to be fine, although PKCS5-padding gets decryption along and some extra garbage (I assume this is due to PKCS5-padding ).

 Out array - BEFORE 0000000000000000000000000000000000000000000000000000000000000000 Decrypting at 0 of 18 Decrypting at 16 of 18 HEX : B00FE0383F2E3CBB95A5A28FA91923FA00 Decrypting :   8?.<      #  With Key : I'm a secret key Becomes : no passwordHQ EZ  - =%.7 n Out array - AFTER 6E6F2070617373776F72644851030303C7457F5ACCF12DAA053D252E3708846E 

The above is deduced from my code, no passwordHQ ( 6E6F2070617373776F72644851 ) is the expected output, but you can see that the filling is decoded 030303 , followed by the garbage C7457F5ACCF12DAA053D252E3708846E .

So, how do I install the add-on in OpenSSL?

I expected that there would be an AES_set_padding function (or similar), but I obviously missed it in the documentation.

0
source share
1 answer

Try using the higher level function defined in EVP_ * . PKCS # 7 is standard for these features. Note that the PKCS # 5 add-on is officially an 8-byte block cipher .

After some searching, I found that evp.h should contain:

 const EVP_CIPHER *EVP_aes_128_ecb(void); 

which you should use with

 int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char *key, unsigned char *iv); 

Additional information on EVP features suggests that it automatically uses the correct add-on. IV, of course, is ignored for ECB mode, so any pointer should do.

0
source

Source: https://habr.com/ru/post/885418/


All Articles