使用 DES/3DES 和 python

using DES/3DES with python(使用 DES/3DES 和 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

python count duplicate in list(python在列表中计数重复)
drop_duplicates not working in pandas?(drop_duplicates 在 pandas 中不起作用?)
Get unique items from list of lists?(从列表列表中获取唯一项目?)
How to install python package with a different name using PIP(如何使用 PIP 安装具有不同名称的 python 包)
How to quot;select distinctquot; across multiple data frame columns in pandas?(如何“选择不同的?跨越 pandas 中的多个数据框列?)
Intersection of two lists, keeping duplicates in the first list(两个列表的交集,在第一个列表中保留重复项)