using DES/3DES with python

后端 未结 2 1002
-上瘾入骨i
-上瘾入骨i 2020-12-28 09:25

what is the best module /package in python to use des /3des for encryption /decryption. could someone provide example to encrypt data with des/3des on python.

2条回答
  •  粉色の甜心
    2020-12-28 09:38

    You can use the M2Crypto Python wrapper for OpenSSL. It has the advantage of being fast (as fast as OpenSSL), but the disadvantage of the documentation being limited.

    Here is the example from my answer to "How to 3DES encrypt in Python using the M2Crypto wrapper?"

    with open(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()
    

提交回复
热议问题