python中使用des/3des進行加密/解密的最佳模塊/軟件包是什麼? 有人可以提供一個例子,用python的des/3des加密數據。使用DES/3DES與python
10
A
回答
17
pyDes可用於DES和3DES。示例用法:
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
一種替代方案是,它支持大量的加密算法(包括DES & 3DES)的Chillkat Python Encryption Library,但它是不自由。示例用法:
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安全如今,有很多更好的選擇(AES擺在首位,如果你想堅持以標準或Twofish,Blowfish等...)
6
您可以使用M2Crypto Python包裝OpenSSL。它具有快速的優點(與OpenSSL一樣快),但文檔的缺點是有限的。
這裏是my answer到"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()
+0
您擁有的M2Crypto鏈接已經死亡。 – BlackVegetable 2014-10-25 01:05:41
相關問題
- 1. 與使用Python
- 2. 與使用Python
- 3. 與使用python
- 4. 與Python使用forever.js
- 5. 使用oauth2與python
- 6. 使用Python與python驗證Promos
- 7. 使用DLL與python和ctypes
- 8. 使用tor與urllib python
- 9. 使用撒克遜與Python
- 10. 使用Boost Python與弱點?
- 11. 使用Python的smtplib與Tor
- 12. 使用boto與Python的
- 13. 使用scipy.integrate.odeint與字典[Python]
- 14. 使用管道與python
- 15. 使用Blobstore Python API與ajax
- 16. 使用QWebFrame.setContent()與unicode(Python + PySide)
- 17. 使用EXEC()與Python 3.2
- 18. 基本與使用python
- 19. 使用機械化與Python
- 20. 如何使用python與JavaScript?
- 21. 使用XMLHttpRequest()PUT與GAE Python
- 22. 如何使用python與scrapy?
- 23. 與Python一起使用表
- 24. 與Python一起使用Crontab
- 25. 與linkedin使用python-social-auth
- 26. 使用Python與pygame的
- 27. 正確使用NTLK與python
- 28. 使用deferred.defer與Python 2.7
- 29. 使用PLY與python -OO?
- 30. 使用macports安裝python 3.6後使用python與終端錯誤
>>>打印encStr \無 – Ska 2011-09-07 17:07:37
打印 」加密的例子:%R「 %d --->爲什麼沒有括號 – CaTx 2017-10-05 02:48:24
不能CONCAT字節爲int ----> python 3中的錯誤??? – Mehrdad 2017-12-19 07:36:10