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 ...
随机推荐
- AppBox中main树节点单击事件JS(还有叶子的节点的页面链接)
AppBox中main.aspx.csif (menu.IsTreeLeaf) { node.Leaf = true; ...
- Microsoft Dynamics CRM2011 Javascript
一.CRM2011 Javascript 禁用子网格 // Disable a subgrid on a form function disableSubgrid(subgridName) { ...
- hello word 应用程序的编写
1.各类文件的书写 src中的文件: hello文件夹中的Makefile文件 # # Copyright (C) - OpenWrt.org # # This is free software, l ...
- 用exec调用带有output输出参数的存储过程
用exec调用带有output输出参数的存储过程,想要得到输出参数的值,必须在调用参数后面加output关键字,如: declare @value int exec up_test 2,3,@v ...
- Windows Server 2008 R2 3389端口更改
Windows Server 2008 R2 3389端口更改 2016-04-28 23:08 4734人阅读 评论(0) 收藏 举报 分类: Windows(61) 版权声明:本文为博主原创文 ...
- windows下隐藏磁盘分区
在一定情况下有的人会想隐藏掉部分分区,比如双系统的情况 有两种方式 方法1: 删除盘符,适合在双系统的情况下隐藏掉另外一个系统相关的分区 请注意是删除盘符 不是删除分区 此电脑右键管理 点击磁盘管理 ...
- 【Spring学习笔记-MVC-12】Spring MVC视图解析器之ResourceBundleViewResolver
场景 当我们设计程序界面的时候,中国人希望界面是中文,而美国人希望界面是英文. 我们当然希望后台代码不需改变,系统能够通过配置文件配置,来自己觉得是显示中文界面还是英文界面. 这是,Spring mv ...
- linux上很方便的上传下载文件工具rz和sz使用介绍
简单说就是,可以很方便地用这两个sz/rz工具,实现Linux下和Windows之间的文件传输(发送和接收),速度大概为10KB/s,适合中小文件.rz/sz 通过Zmodem协议传输数据 一般来 ...
- 解决“Can't bind to local 8630 for debugger”错误--查杀多余进程
Can't bind to local 8630 for debugger 表明本地8630端口被占用 1.Windows平台 在windows命令行窗口下执行: 1.查看所有的端口占用情况 C:\& ...
- java编译器知识
代码编译器: 代码: 编译就是讲一种代码编译成计算机可以理解的指令. ================================================================= ...