The problem is the addition. The mcrypt extension for PHP uses only ZeroPadding. This means that plaintext is filled with 0x00 bytes until a multiple of the block size is reached.
PKCS # 5 / PKCS # 7, on the other hand, fills it with bytes, which indicate the number of bytes skipped to the next multiple block size. The block size for DES is 8 bytes.
Thus, you either need to fill in the plaintext in php (see this code: A: How to add / remove the PKCS7 add-on from the encrypted AES string? ) Or use another cipher in ColdFusion, for example "DES/ECB/NoPadding" . I recommend the first, because if you use NoPadding, the plaintext should already be a multiple of the block size.
$key = " $224455@ "; $Valor = "TESTE"; function pkcs7pad($plaintext, $blocksize) { $padsize = $blocksize - (strlen($plaintext) % $blocksize); return $plaintext . str_repeat(chr($padsize), $padsize); } $base = chop(base64_encode(mcrypt_encrypt(MCRYPT_DES, $key, pkcs7pad($Valor, 8), MCRYPT_MODE_ECB)));
Result:
qOQnhdxiIKs =
Remember to unpack the recovered plaintext if you decrypt it in PHP.
Artjom B.
source share