Archived Forum Post

Index of archived forum posts

Question:

Chilkat/ PHP mcrypt AES encryption compatibility

Mar 04 '16 at 10:38

I try to decode a string encode in php using : mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $data, MCRYPT_MODE_ECB)

And it seems to didn't work in C++ with :

    CkCrypt2 Crypt;
    Crypt.put_CryptAlgorithm("aes");
    Crypt.put_CipherMode("ebc");
    Crypt.put_PaddingScheme(3);
    Crypt.put_KeyLength(256);
    Crypt.put_EncodingMode("base64");
    Crypt.SetEncodedKey(AES_KEY,"ascii");


Answer

AES is not exactly synonymous with “Rijndael”. AES is a (restricted) variant of Rijndael.

AES has a fixed block size of 128 bits and a key size of 128, 192, or 256 bits, whereas Rijndael is specified with block and key sizes in any multiple of 32 bits, both with a minimum of 128 and a maximum of 256 bits.

PHP provides a general implementation Rijndael algorithm. The PHP mcrypt API is unintentionally misleading because most users would think that specifying MCRYPT_RIJNDAEL_256 means that you’ll get 256-bit encryption. This is NOT the case. The MCRYPT_RIJNDAEL_256 is actually setting the block size of the algorithm (not the strength).