I'm trying to encrypt then base64_encode a string using Python, and base64_decode then decrypt the result with Ruby, but the string is messed up.
I don't see any difference in the two methods. I tried using the 128-bit AES-CFB algorithm, but had no success.
Here's my Python code:
from Crypto.Cipher import AES
from Crypto.Util.randpool import RandomPool
from base64 import standard_b64encode, standard_b64decode
key = "abcdefghijklmnop"
en = AES.new(key, AES.MODE_CFB, "0000000000000000")
cipher = en.encrypt("apple")
cipher64 = standard_b64encode(cipher)
cipher64 contains: WqF9Zj0=
My Ruby code is:
require "openssl"
require 'digest/sha2'
require 'base64'
de = OpenSSL::Cipher::Cipher.new("aes-128-cfb")
de.decrypt
de.key = "abcdefghijklmnop"
de.iv = "0000000000000000"
plain = de.update("WqF9Zj0=".unpack('m')[0])
de.final
puts plain
plain contains a different string than "apple". I get the same result if my string's length is 16, to avoid a padding problem.
I guess it's a parameter problem, but I can't figure out what. Does anyone have an idea?