问题描述
什么是python中最好的模块/包使用des / 3des加密/解密。
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.
推荐答案
可用于DES和3DES。示例用法:
pyDes can be used for both, DES and 3DES. Sample usage:
from pyDes import *
data = "Please encrypt my data"
k = des("DESCRYPT", CBC, "\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5)
d = k.encrypt(data)
print "Encrypted: %r" % d
print "Decrypted: %r" % k.decrypt(d)
assert k.decrypt(d, padmode=PAD_PKCS5) == data
a href =http://www.chilkatsoft.com/python-encryption.asp =nofollow noreferrer> Chillkat Python加密库 ,它支持大量的加密算法包括DES& 3DES),但不是免费的。示例用法:
An alternative is the Chillkat Python Encryption Library which supports a lot of encryption algorithms (including DES & 3DES), but it is not free. Sample usage:
crypt.put_CryptAlgorithm("des")
crypt.put_CipherMode("cbc")
crypt.put_KeyLength(64)
crypt.put_PaddingScheme(0)
crypt.put_EncodingMode("hex")
ivHex = "0001020304050607"
crypt.SetEncodedIV(ivHex,"hex")
keyHex = "0001020304050607"
crypt.SetEncodedKey(keyHex,"hex")
encStr = crypt.encryptStringENC("The quick brown fox jumps over the lazy dog.")
print encStr
decStr = crypt.decryptStringENC(encStr)
print decStr
无论如何,我希望你知道,现在没有DES和3DES被视为paritcularly安全,有许多更好的替代你想坚持标准,或Twofish,Blowfish等...)
Anyway, I hope that you are aware that neither DES nor 3DES are considered paritcularly safe nowadays, there are many better alternatives (AES in the first place if you want to stick to standards, or Twofish, Blowfish, etc...)
这篇关于使用DES / 3DES与python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!