DES 加密 转码 脱敏

 1 from pyDes import des, CBC, PAD_PKCS5
 2 import binascii
 3 
 4 # 秘钥
 5 KEY = 'mHAxsLYz'
 6 
 7 
 8 from pyDes import des, CBC, PAD_PKCS5
 9 import binascii
10 
11 # 秘钥
12 KEY = 'mHAxsLYz'
13 
14 
15 def des_encrypt(s):
16     """
17     DES 加密
18     :param s: 原始字符串
19     :return: 加密后字符串,16进制
20     """
21     secret_key = KEY
22     iv = secret_key
23     k = des(secret_key, CBC, iv, pad=None, padmode=PAD_PKCS5)
24     en = k.encrypt(s, padmode=PAD_PKCS5)
25     return bytes.decode(binascii.b2a_hex(en))
26 
27 
28 def des_descrypt(s):
29     """
30     DES 解密
31     :param s: 加密后的字符串,16进制
32     :return:  解密后的字符串
33     """
34     secret_key = KEY
35     iv = secret_key
36     k = des(secret_key, CBC, iv, pad=None, padmode=PAD_PKCS5)
37     de = k.decrypt(binascii.a2b_hex(s), padmode=PAD_PKCS5)
38     return bytes.decode(de)

 

posted @ 2019-10-22 14:38  cup_leo  阅读(378)  评论(0编辑  收藏  举报