pyDes库 实现python的des加密
下载及简介地址:https://twhiteman.netfirms.com/des.html
如需要在python中使用des加密,可以直接使用pyDes库加密,该库提供了CBC和ECB两种加密方式。
1、Windows下安装
下载后pyDes-x.x.x.zip并解压后,里面有setup.py文件,使用命令 setup.py --help可查看详细使用。
你可以使用命令 python setup.py install 命令安装,也可以直接将压缩包内的pyDes.py拷贝到本地的python lib库下直接开始使用
2、 使用
使用参数如下(拷贝自上述提供的地址):
Class initialization
--------------------
pyDes.des(key, [mode], [IV], [pad], [padmode])
pyDes.triple_des(key, [mode], [IV], [pad], [padmode]) key -> Bytes containing the encryption key. 8 bytes for DES, 16 or 24 bytes
for Triple DES
mode -> Optional argument for encryption type, can be either
pyDes.ECB (Electronic Code Book) or pyDes.CBC (Cypher Block Chaining)
IV -> Optional Initial Value bytes, must be supplied if using CBC mode.
Length must be 8 bytes.
pad -> Optional argument, set the pad character (PAD_NORMAL) to use during
all encrypt/decrpt operations done with this instance.
padmode -> Optional argument, set the padding mode (PAD_NORMAL or PAD_PKCS5)
to use during all encrypt/decrpt operations done with this instance. I recommend to use PAD_PKCS5 padding, as then you never need to worry about any
padding issues, as the padding can be removed unambiguously upon decrypting
data that was encrypted using PAD_PKCS5 padmode. Common methods
--------------
encrypt(data, [pad], [padmode])
decrypt(data, [pad], [padmode]) data -> Bytes to be encrypted/decrypted
pad -> Optional argument. Only when using padmode of PAD_NORMAL. For
encryption, adds this characters to the end of the data block when
data is not a multiple of 8 bytes. For decryption, will remove the
trailing characters that match this pad character from the last 8
bytes of the unencrypted data block.
padmode -> Optional argument, set the padding mode, must be one of PAD_NORMAL
or PAD_PKCS5). Defaults to PAD_NORMAL
Example
-------
from pyDes import * # For Python3, you'll need to use bytes, i.e.:
# data = b"Please encrypt my data"
# k = des(b"DESCRYPT", CBC, b"\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5) 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) == dat 以下是本人使用的例子,使用CBC加密的方式:
import base64
from pyDes import * Des_Key = "BHC#@*UM" # Key
Des_IV = "\x22\x33\x35\x81\xBC\x38\x5A\xE7" # 自定IV向量 def DesEncrypt(str):
k = des(Des_Key, CBC, Des_IV, pad=None, padmode=PAD_PKCS5) EncryptStr = k.encrypt(str) return base64.b64encode(EncryptStr) #转base64编码返回
pyDes库 实现python的des加密的更多相关文章
- PYTHON实现DES加密及base64源码
要求是实现DES加密,解密,我是用python实现的,还是有挺多坑的,改bug就改了挺久,加密实现后,解密过程就比较轻松. 另外,附加base64编码源码 要求:输入秘钥为64位二进制数(有效位为56 ...
- python实现DES加密算法和3DES加密算法
pyDes.py ############################################################################# # Documentati ...
- python进行des加密解密,而且可以与JAVA进行互相加密解密
import binasciifrom pyDes import des, CBC, PAD_PKCS5import uuidimport time # pip install -i https:// ...
- 使用Python进行3DES加密-pyDes
pyDes.py源码 ############################################################################# # Documenta ...
- python和c#通用一致的des加密采用CBC和PKCS7
在python下可以下载pydes 下载地址为 http://pydes.sourceforge.net/ 在c#下实现des加密较为简单,如下: using System; using System ...
- python 和 C# DES加密
C# code: using System; using System.IO; using System.Security.Cryptography; using System.Text; names ...
- paip.提升安全性----Des加密 java php python的实现总结
paip.提升安全性----Des加密 java php python的实现总结 /////////// uapi private static String decryptBy ...
- Python实现基于DES加密源码的文本加密器
这是自行制作的一个DES文本加密工具 最终效果图: 本加密器支持UTF-8字符的加解密(包含中文),由于其中的编码方式与常用编码方式不同,加密结果与网上工具不同,但是能实现正常加解密. 最终目标: 目 ...
- C++ 使用openssl库实现 DES 加密——CBC模式 && RSA加密——公加私解——私加公解
之前工作上需要用C++把软件生成的用户序列号用des加密cbc的模式,加密后为二进制,转化为十六进制,然后提供给java写的授权码管理平台. java平台会根据用户序列号,生成一个授权码,授权码是用r ...
随机推荐
- Selenium2+python自动化42-判断元素(expected_conditions)
前言 经常有小伙伴问,如何判断一个元素是否存在,如何判断alert弹窗出来了,如何判断动态的元素等等一系列的判断,在selenium的expected_conditions模块收集了一系列的场景判断方 ...
- 【Spring学习笔记-5】Spring中的抽象bean以及bean继承
*.hl_mark_KMSmartTagPinkImg{background-color:#ffaaff;}*.hl_mark_KMSmartTagBlueImg{background-color:# ...
- 【Oracle学习笔记-5--】集合操作之union,intersect和minus操作
--union并操作 select e.employee_id,e.last_name from hr.employees e where e.last_name like 'C%' union se ...
- python 可视化 二维坐标标注等等
基本画图操作: import matplotlib.pyplot as plt import numpy as np x = np.linspace(-3,3,50) y1 = 2*x+1 y2 = ...
- VBA 自动得到分数
' 将一个正数除以 y 返回一个整数或分数 Function RFs(ByVal x As Integer) As String Then RFs = Exit Function End If Dim ...
- override的实现原理
转载 http://blog.csdn.net/fan2012huan/article/details/51007517 基于基类的调用和基于接口的调用,从性能上来讲,基于基类的调用性能更高 .因为i ...
- Linux 期中架构 inotify
全网备份数据同步方案 备份网站内部人员信息 不能解决外部(人员)上传数据的备份 定时任务最短执行的周期为一分钟,采用定时任务方式,有时可能造成一分钟内的数据丢失 因此对于重要数据需要采用实时同步的方 ...
- 关于ESXI5.0版本+ Broadcom BCM5720的BUG
主要发生在网卡 Broadcom Corporation NetXtreme BCM5720 Gigabit Ethernet 和ESX 5.0之前的版本. 虚拟机的网络突然不通,必须删除网卡重新创建 ...
- win10的坑之wifi找不到
安装了win10一周以来,win10的坑太多太多,微软搞什么pc/mobile二合一,真是脑残行为. 首先是usb设备无缘无故找不到,据说是和杀毒软件/防火墙有关,后来是关掉了windows defe ...
- 探究CSS中border-top属性的使用
上一节我们介绍了CSS top属性的用法,那么这节关于CSS border-top属性用法学习起来就会轻松一些,border-top 简写属性把上边框的所有属性设置到一个声明中. 本文向大家描述一下C ...