加秘测试
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
449e999d43
commit
0144ae91e8
|
@ -5,7 +5,11 @@ import { getPublicKey } from "@/api/user.js"
|
||||||
export const Crypto = {
|
export const Crypto = {
|
||||||
AES: {
|
AES: {
|
||||||
encrypt: function (plaintext, secretKey) {
|
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) {
|
decrypt: function (ciphertext, secretKey) {
|
||||||
const bytes = CryptoJS.AES.decrypt(ciphertext, secretKey);
|
const bytes = CryptoJS.AES.decrypt(ciphertext, secretKey);
|
||||||
|
@ -31,7 +35,6 @@ export const Encrypt = {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(PublicKey)
|
|
||||||
let encryptor = new JSEncrypt()
|
let encryptor = new JSEncrypt()
|
||||||
encryptor.setPublicKey(PublicKey)
|
encryptor.setPublicKey(PublicKey)
|
||||||
return encryptor.encrypt(plaintext)
|
return encryptor.encrypt(plaintext)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Encrypt, Crypto } from "./crypto";
|
import { Encrypt, Crypto } from "./crypto";
|
||||||
export const encryptConfig = async (config) => {
|
export const encryptConfig = async (config) => {
|
||||||
let secretKey = randomRange(10, 43);
|
let secretKey = randomRange(32, 32);
|
||||||
let encryptSecretKey = await Encrypt.encrypt(secretKey); // 密钥进行非对称加密
|
let encryptSecretKey = await Encrypt.encrypt(secretKey); // 密钥进行非对称加密
|
||||||
if (encryptSecretKey) {
|
if (encryptSecretKey) {
|
||||||
config.headers['X-Encrypted-Key'] = 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]') {
|
if (config.data && Object.prototype.toString.call(config.data) === '[object Object]') {
|
||||||
Object.keys(config.data).forEach(async key => {
|
Object.keys(config.data).forEach(async key => {
|
||||||
config.data[key] = Crypto.AES.encrypt(config.data[key], secretKey)
|
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])
|
// config.data[key] = await Encrypt.encrypt(config.data[key])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue