一、python
1、 des3
python平台的DES3 + base64 加密解密, 有两个常用的库pycrypto和pyDes
1)pycrypto
des3.py
#coding=utf-8
from Crypto.Cipher import _DES3
import base64
import json
BS = _DES3.block_size
def pad(s):
return s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
#定义 padding 即 填充 为PKCS7
def unpad(s):
return s[0:-ord(s[-1])]
class prpcrypt():
def __init__(self, key):
self.key = key
self.mode = _DES3.MODE_CBC #模式为CBC
self.iv = IV #self.iv 为 IV 即偏移量,ECB模式不使用IV
# DES3的加密模式为CBC
def encrypt(self, text):
text = pad(text)
cryptor = _DES3.new(self.key, self.mode, self.iv)
x = len(text) % 8
if x != 0:
text = text + '