欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

python的des和3des加解密

发布时间:2025/4/5 python 52 豆豆
生活随笔 收集整理的这篇文章主要介绍了 python的des和3des加解密 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

1.加密:

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 bytesfor Triple DES mode -> Optional argument for encryption type, can be eitherpyDes.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 duringall 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.

实例:

Example ------- from pyDes import *data = "Please encrypt my data" k = des("DESCRYPT", CBC, "\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5) # 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) d = k.encrypt(data) print "Encrypted: %r" % d print "Decrypted: %r" % k.decrypt(d) assert k.decrypt(d, padmode=PAD_PKCS5) == data

 

转载于:https://www.cnblogs.com/davidwang456/p/9108092.html

总结

以上是生活随笔为你收集整理的python的des和3des加解密的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。