加秘测试
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 = {
|
||||
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)
|
||||
|
|
|
@ -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])
|
||||
})
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ service.interceptors.request.use(
|
|||
config.headers['Accept-Language'] = language === 'en' ? 'en-US,en;q=0.5' : 'zh-CN,zh;q=0.9'
|
||||
config.headers['TimeZoneId'] = moment.tz.guess()
|
||||
// if (config.ENCRYPT) {
|
||||
// try{
|
||||
// try {
|
||||
// config = await encryptConfig(config)
|
||||
// }catch(err){
|
||||
// } catch (err) {
|
||||
// console.log(err)
|
||||
// }
|
||||
// }
|
||||
|
|
Loading…
Reference in New Issue