How do I convert this to Python? What I'm confused is the random vi.
PHP
public function fnEncrypt($sValue, $sSecretKey)
{
$sValue = $this->pkcs5_pad($sValue, mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, 'ecb'));
return rtrim(
base64_encode(
mcrypt_encrypt(
MCRYPT_RIJNDAEL_128,
$sSecretKey, $sValue,
MCRYPT_MODE_ECB,
mcrypt_create_iv(
mcrypt_get_iv_size(
MCRYPT_RIJNDAEL_128,
MCRYPT_MODE_ECB
),
MCRYPT_RAND)
)
), "\0"
);
}
UPDATE:
this works exactly how it should!
Python
secret_key = 'he21jodkio1289ij'
value = 'hello'
BLOCK_SIZE = 16
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
PADDING = '\0'
EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
cipher = AES.new(secret_key, AES.MODE_ECB)