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); // 对数据进行解密 };