import JSEncrypt from 'jsencrypt/bin/jsencrypt'

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

const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMkyd3UWDgDyk70PlCrQJimVswNV8zk8d5DvVpvjtCW3xVuXOACHDQDUsFgHYh/B8A43eADR6+2b/776Bz/ZhjUCAwEAAQ=='

const privateKey = 'MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAyTJ3dRYOAPKTvQ+UKtAmKZWzA1XzOTx3kO9Wm+O0JbfFW5c4AIcNANSwWAdiH8HwDjd4ANHr7Zv/vvoHP9mGNQIDAQABAkAFONca5eClK6akAJSC6/YhnC4SRxfSA3zC+UNRNn7Ff8y/3fzhPjzQa9Fg+5kM9gEQylRDTBfFeBpArr5xk9udAiEA9uoWCJFJQYWDE7Xqv9bQszGuSf/ezuKCRa73H1E/1H8CIQDQmbpDRAfBwCcM759pw3DbhOK4EXN6uFg53n9ZqVM7SwIhAPPFspEs11VP+lQ4c5aJAC0abId0jcZVjOY9Uo/hyJIDAiEAs1fHvTdLF/f1WvjVbJ/ccs8wASL3zsWZDL/Pa63ZYjsCIF9qoBzAEka+ZbRoxvcI9pLx7GFFCvkbOrDlvC+vZO3s'

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