Using PyCrypto (although I've tried this in ObjC with OpenSSL bindings as well) :
from Crypto.Cipher import DES
import base64
obj=DES.new('abcdefgh', DES.MODE_ECB)
plain="Guido van Rossum is a space alien.XXXXXX"
ciph=obj.encrypt(plain)
enc=base64.b64encode(ciph)
#print ciph
print enc
outputs a base64 encoded value of :
ESzjTnGMRFnfVOJwQfqtyXOI8yzAatioyufiSdE1dx02McNkZ2IvBg==
If you were in the interpreter, ciph will give you
'\x11,\xe3Nq\x8cDY\xdfT\xe2pA\xfa\xad\xc9s\x88\xf3,\xc0j\xd8\xa8\xca\xe7\xe2I\xd15w\x1d61\xc3dgb/\x06'
Easy enough. I should be able to pipe this output to OpenSSL and decode it :
I test to make sure that the b64 decode works -
python enctest.py | openssl enc -base64 -d
+ python enctest.py
+ openssl enc -base64 -d
,?Nq?DY?T?pA???s??,?jب???I?5w61?dgb/
Not pretty, but you can see that it got decoded fine, "dgb" and "Nq" are still there.
But go for the full thing :
python enctest.py | openssl enc -base64 -d | openssl enc -nosalt -des-ecb -d -pass pass:abcdefgh
+ python enctest.py
+ openssl enc -nosalt -des-ecb -d -pass pass:abcdefgh
+ openssl enc -base64 -d
bad decrypt
15621:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:evp_enc.c:461:
j?7????vc]???LE?m³??q?
What am I doing wrong? I've tried using -k abcdefgh -iv 0000000000000000 or typing in the password interactively - same problem.