使用 DES/3DES 和 python [英] using DES/3DES with python

查看:26
本文介绍了使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆