加密
``
import base64
from Crypto.Cipher import AES, DES3
def password_encry(password):
def add_to_16(password):
while len(password) % 16 != 0:
password += '\0'
return str.encode(password) # 返回bytes
key = 'saierwangluo' # 密钥
aes = AES.new(add_to_16(key), AES.MODE_ECB) # 初始化aes加密器
des3 = DES3.new(add_to_16(key), DES3.MODE_ECB) # 初始化3des加密器
encrypted_text = str(base64.encodebytes(aes.encrypt(add_to_16(password))), encoding='utf8').replace('\n', '') # aes加密
des_encrypted_text = str(base64.encodebytes(des3.encrypt(add_to_16(encrypted_text))), encoding='utf8').replace(
'\n', '') # 3des加密
# 返回加密后数据
return des_encrypted_text
解密
``
import base64
from Crypto.Cipher import AES, DES3
def signInCheck(pw):
def add_to_16(text):
while len(text) % 16 != 0:
text += '\0'
return str.encode(text) # 返回bytes
key = 'xxxxxxxxxx' # 与加密一致
des_encrypted_text = pw
aes = AES.new(add_to_16(key), AES.MODE_ECB) # 初始化加密器
des3 = DES3.new(add_to_16(key), DES3.MODE_ECB) # 初始化加密器
des_text_decrypted = str(
des3.decrypt(base64.decodebytes(bytes(des_encrypted_text, encoding='utf8'))).rstrip(b'\0').decode(
"utf8")) # 解密
text_decrypted = str(
aes.decrypt(base64.decodebytes(bytes(des_text_decrypted, encoding='utf8'))).rstrip(b'\0').decode(
"utf8")) # 解密
return text_decrypted