I've inherited some old PHP code that needs to be switched to Python. Given an encryption key in plain ascii, it is supposed to read in encrypted data from a file and spit out the decrypted version. For some reason, the PHP code works but the Python code does not. What am I missing?
The block sizes on both systems are reporting 32. The key size in PHP is reporting to be 24.
PHP
<?php
$key = 'asdf';
$enc = fopen('encrypted.txt', 'r');
$message = fread($enc, 1024*1024);
$td = mcrypt_module_open('rijndael-256', '', 'cfb', '');
$iv = substr($message,0,mcrypt_enc_get_iv_size($td));
$message = substr($message, mcrypt_enc_get_iv_size($td));
mcrypt_generic_init($td, $key, $iv);
$message = mdecrypt_generic($td, $message);
print substr($message, 0, 32);
Python
import mcrypt
key = 'asdf'
KEY_SIZE = 24
inp = open('encrypted.txt')
encrypted_data = inp.read()
mc = mcrypt.MCRYPT('rijndael-256', 'cfb')
iv = encrypted_data[0:mc.get_iv_size()]
encrypted_data = encrypted_data[mc.get_iv_size():]
mc.init(key.ljust(KEY_SIZE, '\0'), iv)
output = mc.decrypt(encrypted_data)
print output[0:32]