PyCrypto uses a different segment_size
When encoding, specify segment_size and enter plain text.
from base64 import standard_b64encode from Crypto.Cipher import AES def pad(x, n=16): p = n - (len(x) % n) return x + chr(p) * p key = "abcdefghijklmnop" en = AES.new(key=key, mode=AES.MODE_CFB, IV="0" * 16, segment_size=128) cipher = en.encrypt(pad("apple")) cipher64 = standard_b64encode(cipher) print cipher64
Using the code above, you will get apple\x03\x03\x03 . On the Ruby side, you have to remove the pad.
Ruby part (decoding):
require "openssl" de = OpenSSL::Cipher::Cipher.new("aes-128-cfb") de.decrypt de.key = "abcdefghijklmnop" de.iv = "0000000000000000" plain = de.update(ARGV[0].unpack('m')[0]) + de.final plain = plain[0...-plain[-1].ord] puts plain
Alternatively, you can use M2Crypto, which does not need to remove the strip on the Ruby side:
from base64 import standard_b64encode import M2Crypto.EVP key = "abcdefghijklmnop" iv = "0000000000000000" en = M2Crypto.EVP.Cipher('aes_128_cfb', key, iv, 1) cipher = en.update('apple') + en.final() cipher64 = standard_b64encode(cipher) print cipher64
source share