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. 使用oauth2與python
- 4. 使用Python與python驗證Promos
- 5. 使用Blobstore Python API與ajax
- 6. 使用EXEC()與Python 3.2
- 7. 使用Python與pygame的
- 8. 使用Python的smtplib與Tor
- 9. 如何使用python與JavaScript?
- 10. 與linkedin使用python-social-auth
- 11. 使用機械化與Python
- 12. 使用管道與python
- 13. 使用QWebFrame.setContent()與unicode(Python + PySide)
- 14. 使用撒克遜與Python
- 15. 基本與使用python
- 16. 使用scipy.integrate.odeint與字典[Python]
- 17. 使用Boost Python與弱點?
- 18. 使用tor與urllib python
- 19. 與Python一起使用表
- 20. 使用macports安裝python 3.6後使用python與終端錯誤
- 21. 系統python與用戶python
- 22. 使用pycrypto AppEngine上與Python 2.7
- 23. 發送郵件使用Python與#標籤#
- 24. 解析使用lxml和請求與python
- 25. 運行Sqoop與使用python 3子
- 26. 使用python與網頁交互
- 27. 使用ElementTree分析XML與python
- 28. 使用撇號與python的子進程
- 29. 存儲和MSSQL使用JSON與Python
- 30. 使用rPython進口numply與Python 3.5
>>>打印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