0

I want to encrpt using TripleDES-CBC-PKCS5.

I am testing python code and openssql for encrypting.

key = md5("card")

using pyDes.py:

def enc(data):
    m = hashlib.md5()
    m.update("card")
    key = m.digest()  
    k = triple_des(key, CBC, "\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5)
    d = k.encrypt(data=data, padmode=PAD_PKCS5)
    return  base64.b64encode(d)


enc("b47650")

result : h93d5If6mYU=

using openssl:

> cat test 
b47650
> openssl des3 -in test.file -e -a -p -nosalt -K 5dd2199ad68327cc76d583b057aee7d5 -iv 00000000


key=5DD2199AD68327CC76D583B057AEE7D50000000000000000
iv =0000000000000000
MMSBm/mbxJU=

why different?

jww
  • 97,681
  • 90
  • 411
  • 885
ash84
  • 787
  • 3
  • 12
  • 33
  • You should probably be using `EVP_*` functions. See [EVP Symmetric Encryption and Decryption](https://wiki.openssl.org/index.php/EVP_Symmetric_Encryption_and_Decryption) on the OpenSSL wiki. In fact, you should probably be using authenticated encryption because it provides *both* confidentiality and authenticity. See [EVP Authenticated Encryption and Decryption](https://wiki.openssl.org/index.php/EVP_Authenticated_Encryption_and_Decryption) on the OpenSSL wiki. – jww Jun 01 '15 at 04:10
  • 1
    Related, [How to AES encrypt/decrypt files using Python/PyCrypto in an OpenSSL-compatible way?](http://stackoverflow.com/q/16761458) or [How to encrypt a file with python but can be decrypted using the shell?](http://stackoverflow.com/q/15129045) – jww Jun 01 '15 at 04:14

0 Answers0