Skip to content Skip to sidebar Skip to footer

How To 3des Encrypt In Python Using The M2crypto Wrapper?

I have a working test of a hardware device that uses RSA encryption, in Python using M2Crypto. Now I need to test a similar device that uses 3DES encryption. But I can't figure o

Solution 1:

See here. There is reference for the following DES ciphers : 'des_ede_ecb', 'des_ede_cbc', 'des_ede_cfb', 'des_ede_ofb', 'des_ede3_ecb', 'des_ede3_cbc', 'des_ede3_cfb', 'des_ede3_ofb'.

The homepage seems to be here now.

Solution 2:

The following code worked for me:

withopen(keyfile, 'rb') as f:
    key = f.read()
encrypt = 1
cipher = Cipher(alg='des_ede3_ecb', key=key, op=encrypt, iv='\0'*16)
ciphertext = cipher.update(plaintext)
ciphertext += cipher.final()

Note the keyfile is a 24-byte (binary) file with parity set as sometimes required for DES.

Note also that the iv argument is (I believe) ignored when using 'des_ede3_ecb', but I couldn't pass None.)

Post a Comment for "How To 3des Encrypt In Python Using The M2crypto Wrapper?"