You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
597 B
JavaScript
25 lines
597 B
JavaScript
|
1 week ago
|
import JSEncrypt from 'jsencrypt';
|
||
|
|
import {
|
||
|
|
getGlobalData
|
||
|
|
} from '@/store/index.js'
|
||
|
|
|
||
|
|
|
||
|
|
const {
|
||
|
|
RSA_PUBLIC_KEY: publicKey,
|
||
|
|
RSA_PRIVATE_KEY: privateKey
|
||
|
|
} = getGlobalData(['RSA_PUBLIC_KEY', 'RSA_PRIVATE_KEY'])
|
||
|
|
|
||
|
|
|
||
|
|
// 加密
|
||
|
|
export const encrypt = (txt) => {
|
||
|
|
const encryptor = new JSEncrypt();
|
||
|
|
encryptor.setPublicKey(publicKey); // 设置公钥
|
||
|
|
return encryptor.encrypt(txt); // 对数据进行加密
|
||
|
|
};
|
||
|
|
|
||
|
|
// 解密
|
||
|
|
export const decrypt = (txt) => {
|
||
|
|
const encryptor = new JSEncrypt();
|
||
|
|
encryptor.setPrivateKey(privateKey); // 设置私钥
|
||
|
|
return encryptor.decrypt(txt); // 对数据进行解密
|
||
|
|
};
|