1. JS实现AES加密
var CryptoJS = require('./package'); // package文件是cryptoJS
var plaintext = '{"did":"a","dname":"Chrome"}';var key = CryptoJS.lib.WordArray.create([929392180,1650538033,1681023538,1647784550
]);
var iv = CryptoJS.lib.WordArray.create([929392180,1650538033,1681023538,1647784550
]);var encrypted = CryptoJS.AES.encrypt(plaintext, key, {iv: iv,padding: CryptoJS.pad.Pkcs7
});var ciphertext = encrypted.toString();
console.log(ciphertext);
2. Python实现AES加密
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
from Crypto.Util.number import long_to_bytes
import base64t = '{"did":"a","dname":"Chrome"}'
latin = [929392180, 1650538033, 1681023538, 1647784550]
byte_array = b''.join([long_to_bytes(num, 4) for num in latin])key = byte_array
iv = byte_array
cipher = AES.new(key, AES.MODE_CBC, iv)
ciphertext = cipher.encrypt(pad(t.encode('utf-8'), AES.block_size))
p = base64.b64encode(ciphertext).decode('utf-8')
print(p)
3. Python实现RSA加密
import base64
from Crypto.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5
from Crypto.PublicKey import RSAak = '3bf111b9cfa710f6'
pem_public_key = """-----BEGIN RSA PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvsY6A9Jze6X5sTgYiEJu
3ALUYc55N6j+nxTEQlsp7vNoyCGabPy8UNrhit9Kjvl6We9GhMfiy6GRrLNksZj9
lncoYvXTzg89F5+hUwM+JIgYbWPM0Rdj43k8EC9DZAqgeU3lPEW46Cg0Hx9Gd9Gc
VNi0hrbTx+QtdC9tYgBifycMdOHDCK6IS/U89ULsqypDmK9XD5kvSHn3or1yldnd
wAa87Y9bnTZzPf5OCknd4d0CQN0hoFeEBu01Vcp/NzHfk02PlQTfTp4T5jQGhYNj
f8xC+TPvTI4Ak26mK7lK+v8cn9X3dJ7Cjqi25gzk441G/YWn/eOFswdgA9UjTIV0
5QIDAQAB
-----END RSA PUBLIC KEY-----
"""
rsakey = RSA.importKey(pem_public_key)
cipher = Cipher_pkcs1_v1_5.new(rsakey)
si = base64.b64encode(cipher.encrypt(ak.encode('utf-8'))).decode('utf-8')
print('si:', si)
4. 读txt每行数据存入列表中
file_path = "C:/Users/Desktop/a.txt" data_list = [] with open(file_path, "r") as file:for line in file:line = line.strip() data_list.append(line)
print(data_list)