加秘测试
continuous-integration/drone/push Build is passing Details

uat_us
DESKTOP-6C3NK6N\WXS 2024-09-20 09:53:33 +08:00
parent 449e999d43
commit 0144ae91e8
3 changed files with 9 additions and 5 deletions

View File

@ -5,7 +5,11 @@ import { getPublicKey } from "@/api/user.js"
export const Crypto = {
AES: {
encrypt: function (plaintext, secretKey) {
return CryptoJS.AES.encrypt(plaintext, secretKey).toString();
return CryptoJS.AES.encrypt(plaintext, CryptoJS.enc.Utf8.parse(secretKey), {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
iv: ''
}).ciphertext.toString(CryptoJS.enc.Base64).replace(/\+/g, '-').replace(/\//g, '_');
},
decrypt: function (ciphertext, secretKey) {
const bytes = CryptoJS.AES.decrypt(ciphertext, secretKey);
@ -31,7 +35,6 @@ export const Encrypt = {
console.log(err)
}
}
console.log(PublicKey)
let encryptor = new JSEncrypt()
encryptor.setPublicKey(PublicKey)
return encryptor.encrypt(plaintext)

View File

@ -1,6 +1,6 @@
import { Encrypt, Crypto } from "./crypto";
export const encryptConfig = async (config) => {
let secretKey = randomRange(10, 43);
let secretKey = randomRange(32, 32);
let encryptSecretKey = await Encrypt.encrypt(secretKey); // 密钥进行非对称加密
if (encryptSecretKey) {
config.headers['X-Encrypted-Key'] = encryptSecretKey;
@ -8,6 +8,7 @@ export const encryptConfig = async (config) => {
if (config.data && Object.prototype.toString.call(config.data) === '[object Object]') {
Object.keys(config.data).forEach(async key => {
config.data[key] = Crypto.AES.encrypt(config.data[key], secretKey)
console.log(config.data[key], 'KEY')
// config.data[key] = await Encrypt.encrypt(config.data[key])
})
}