import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = `-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC4qkbwIKErstK1sFESPEhOShpR
pj4+sOVpJHxl5r/2xLBfA/MrXcAEra5Ro9cXNQSqmLLt8wecoLk/glfa5IdhXV0h
RVQplIVs5z3MxcUa9ptKPHUTgh8xMCBvl8sUJKwkmn4vYWeDfHT22EL7Hr1pTMwU
hF6WiNlWfQTVoF1rhwIDAQAB
-----END PUBLIC KEY-----
`

const privateKey = `-----BEGIN PRIVATE KEY-----
MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBALiqRvAgoSuy0rWw
URI8SE5KGlGmPj6w5WkkfGXmv/bEsF8D8ytdwAStrlGj1xc1BKqYsu3zB5yguT+C
V9rkh2FdXSFFVCmUhWznPczFxRr2m0o8dROCHzEwIG+XyxQkrCSafi9hZ4N8dPbY
QvsevWlMzBSEXpaI2VZ9BNWgXWuHAgMBAAECgYAxNW7h3lAUjPqJYAq6iUXbVvPc
fihoHEuF0Ss1HGBbKd618x+BluHsXTvulXJjxMURkM9diT2mB05WFi3DLtLEM243
w9tDsYq+0nwrRx9NNcxXlMtwlFC1EeAHPn4aKz1gfsT9ISBJvlDr8KK86hyvXnYG
bzhcNRrb9e8LOZHjAQJBAN2y1uqHD7eeMYPYUCpXGNhvCTd9Z6n9GRfClohuB7sZ
64zEDD4KSK+9DGRmwq+ETEeLrGdXBcb6oiUat6OZ+/ECQQDVPJipF875bDXqzJmG
SIkjT1snZoecio+sK0nHKgbDhhbeCQCwPjp35K4JKgGZLqeWWkBmOTzUS4PmPGxu
jrb3AkEAhrFmI50lLnDdMnZU1jSOcsibN+xn8/5CpY3iuUboSYOI+cAOlA7ZdHQO
OF26gLqHQZyZhTt41hhmNNbTpYEjcQJBAJROYerxOS22ukVE6d5AYskhL0fXAqi4
ojZfoR+ZNj0U7KCe6FCr5yRt8zFCevwcO8jRmoq+cnVA1Er0aYH3Vn8CQHU/jOtg
wAtnR3lOcM4428X39l6rJPAuR1CzubMNGMS5grHDhrOVy0gYbZPWU4QUgC82wPq0
yrzs/ckG/wLyzpw=
-----END PRIVATE KEY-----
`
// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

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

