使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

【网站声明】本站部分内容来源于互联网,旨在帮助大家更快的解决问题,如果有图片或者内容侵犯了您的权益,请联系我们删除处理,感谢您的支持!

相关文档推荐

How to draw a rectangle around a region of interest in python(如何在python中的感兴趣区域周围绘制一个矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 检测和跟踪人员?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在图像的多个矩形边界框中应用阈值?)
How can I download a specific part of Coco Dataset?(如何下载 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根据文本方向检测图像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 检测图像中矩形的中心和角度)