The string is encrypted with the following properties (using C#):
myAes.Mode = CipherMode.CBC
myAes.KeySize = 128
myAes.Padding = PaddingMode.PKCS7
myAes.BlockSize = 128
myAes.FeedbackSize = 128
Key: 5753B8AA97BE5B5D9584864DF3134E64
This is my decryption function:
int AESdecrypt(unsigned char *ciphertext, size_t ciphertext_len, unsigned char *key, unsigned char *iv, unsigned char *plaintext)
{
EVP_CIPHER_CTX *ctx;
int len;
int retErrors=1;
int plaintext_len;
/* Create and initialise the context */
if(!(ctx = EVP_CIPHER_CTX_new()))
{
LOGF_TRACE("\t Error in EVP_CIPHER_CTX_new");
EVP_CIPHER_CTX_free(ctx);
return 0;
}
/*
* Initialise the decryption operation. IMPORTANT - ensure you use a key
* and IV size appropriate for your cipher
* In this example we are using 256 bit AES (i.e. a 256 bit key). The
* IV size for *most* modes is the same as the block size. For AES this
* is 128 bits
*/
if(1 != EVP_DecryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, key, iv))
{
LOGF_TRACE("\t Error in EVP_DecryptInit_ex");
EVP_CIPHER_CTX_free(ctx);
return 0;
}
/*
* Provide the message to be decrypted, and obtain the plaintext output.
* EVP_DecryptUpdate can be called multiple times if necessary.
*/
if(1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len))
{
LOGF_TRACE("\t EVP_DecryptUpdate");
EVP_CIPHER_CTX_free(ctx);
return 0;
}
plaintext_len = len;
/*
* Finalise the decryption. Further plaintext bytes may be written at
* this stage.
*/
if(1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len))
{
LOGF_TRACE("\t EVP_DecryptFinal_ex");
EVP_CIPHER_CTX_free(ctx);
return 0;
}
plaintext_len += len;
/* Clean up */
EVP_CIPHER_CTX_free(ctx);
return plaintext_len;
}
However, when I try to decrypt the resulting string has 16 (0x10) extra bytes: (Removed some characters for security reasons).
0000 - 2e 3c 81 6b ed 2e 6b 59-fe 38 ae b7 56 11 1f c2 .<.k..kY.8..V...
0010 - 45 53 54 41 20 45 53 20-55 4e 41 20 50 52 55 45 ESTA ES UNA PRUE
0020 - 42 41 20 44 45 20 43 49-46 52 41 44 4f 20 41 45 BA DE CIFRADO AE
0030 - 53 20 50 41 52 41 20 45-54 48 45 52 4e 45 54 20 S PARA ETHERNET
0040 - XX XX XX XX XX XX XX XX-XX XX XX XXXXXXXX
I'd like to knnow if this is normal and I should just remove the first 16 bytes or how to avoid having those extra bytes (it doesn't feel normal for me).
Could this have anything to do with the IV they're using for encryption?
Thanks.