using DES/3DES with python(使用 DES/3DES 和 python)
问题描述
在 python 中使用 des/3des 进行加密/解密的最佳模块/package 是什么.有人可以提供在 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.
推荐答案
pyDes 可用于 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, " ", 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
<小时>
另一种方法是 Chillkat Python 加密库,它支持很多加密算法(包括 DES 和 3DES),但它不是免费的.示例用法:
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 都被认为是不安全的,有许多更好的选择(如果您想坚持标准,首先选择 AES,或者 Twofish、河豚等……)
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 DES/3DES 和 python


基础教程推荐
- 包装空间模型 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 求两个直方图的卷积 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01