import JSEncrypt from 'jsencrypt'

var publicKey = '-----BEGIN PUBLIC KEY-----\n' +
    'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9eF6XIgicrt7gp5lcMAAAAzNd' +
    'xESvUZaLX83HJp7QmUrH6BqBlshOE3YW5J+3o/QNyfwWhjaWXBxeMOJqbj1PZxv2' +
    '60td2MBBy392FE2crBeJ796bJKvfR4q0CBrhMeTtUZcUXj26qjjnQQCK+8+1Hkbc' +
    'BOeCXPcZKv/yH2PiswIDAQAB\n' +
    '-----END PUBLIC KEY-----'
var privateKey = '-----BEGIN RSA PRIVATE KEY-----\n' +
    'MIICXwIBAAKBgQC9eF6XIgicrt7gp5lcMAAAAzNdxESvUZaLX83HJp7QmUrH6BqB' +
    'lshOE3YW5J+3o/QNyfwWhjaWXBxeMOJqbj1PZxv260td2MBBy392FE2crBeJ796b' +
    'JKvfR4q0CBrhMeTtUZcUXj26qjjnQQCK+8+1HkbcBOeCXPcZKv/yH2PiswIDAQAB' +
    'AoGBAIVDN0yXfHUvrcVXPE+R1z4rAiLuW9zvxrIK1UJAkK1pVCacwp/o/MOlfoaF' +
    'kSzp3UshiPQSvCwvZyh8u5NeLDIJ8fA8qN/T1uC3NQ+2oWnuDFnyLYDCGsZaR7cu' +
    'wD91lXnCO/49dlhovugigBjqaM0ynpu2iWimwjQgp873Y7jZAkEA5FLg1jV8S4I0' +
    'n0NYfNk23WF2WRiWi1uJ35VehWlXJVEbUA7NtNFK/ziulVQPW1zit9MjGxmm9Buf' +
    'yRPDuCpr7QJBANRv005r9409DHeM6XXWTqENZH+iVHbFp2xsVOQ3BbzSBqVhX/v/' +
    'vpjqhgbIHbXGx7IfeFmlEympet27jgPz9R8CQQC0Wb7dlVv77PqR/slLvOw4jD7G' +
    'e8SWiZTrdfo2mZHLmThg0YCtXlDGLsjAjaifu0wedfmZ83ZMBfH+C82ikGe1AkEA' +
    'qaLmXJAQrOMcCncmkidgwHB+WQFaa0GoUQcsvtRFK6OXFQbt68AsBdX40n+IYfhq' +
    'zI0ewI71/2XLrDYx0GxFxwJBAJIgX4feOJPRBCzX1Ky2Fs5J3b9jRw0fFxlsBauq' +
    'xKazEQmpcSkEKvkL63VpcJTtqRwlGhtFsiWsxsp1p3z008w=\n' +
    '-----END RSA PRIVATE KEY-----'
// const generateKeys = () => {
//   const rsa = new JSEncrypt()
//   const keypair = rsa.getKey()
//   publicKey = keypair.getPublicKey()
//   privateKey = keypair.getPrivateKey()
//
//   console.log('公钥：', publicKey)
//   console.log('私钥：', privateKey)
// }

// 加密
export function encrypt (txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  // encryptor.setPrivateKey(privateKey) // 设置公钥
  // console.log(encryptor.encrypt('1698824468777'))
  // console.log(encryptor.decrypt('MWv5TkZ0NcQibD6iNPGTEgZXMltKO8BKPCQe20zAwHArmOXsUBLyb2ZrizvjsjpzbSH6ALyk0mgEpNu4k+0Dw9WExMvJWm5OM/zQpmR9X48DQlmEicQbIzLbtVWRT3YlQmWs/jrPs0+W7rL+dYdjycy/EydWSFeM/pmYpZFhh6A='))
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function decrypt (txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  console.log(encryptor.decrypt('OJICrMZSv7VeT/LCivgUzsTWCDhRPzmtaoMB77aLwXPnGj5VVbHSjA3MohPGABuHF0aCh/rdNT8K1j5CK0c6lKeoyw015vCND/AW1LhcVXZR1FioM8IW70FpM3CcDViNetQCXP9XaCAnFpeeALnRzIGoW6kVpmjiTFYaVvBZluc='))
  return encryptor.decrypt(txt) // 对数据进行解密
}
