import { JSEncrypt } from "jsencrypt";
|
import const_num from "./const_num";
|
|
export default {
|
/**
|
* 非对称加密算法-加密
|
* @param word 需要加密的字符串
|
* @returns {string | false}
|
*/
|
encrypt(word) {
|
let encryptor = new JSEncrypt();
|
let publicKey = const_num.publicKey;
|
encryptor.setPublicKey(publicKey);
|
return encryptor.encrypt(word);
|
},
|
/**
|
* 非对称加密算法-解密
|
* @param word
|
* @param privateKey
|
* @returns {string | false}
|
*/
|
decrypt(word, privateKey) {
|
if (!privateKey) {
|
return "请写入私钥";
|
}
|
let decrypt = new JSEncrypt();
|
decrypt.setPrivateKey(privateKey);
|
return decrypt.decrypt(word);
|
},
|
};
|