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

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

const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCL7reDWNP/Ts9SD/blkfnYJmDa2TCqmRgt8q223oSUFpm85z9miZ2Mby0KJWE2U2aCAwF6vEOWWuvtxp4OEV/BLg4Iab4LSV+YMdDAEdp5fyurGu62Hg2AguogqJdZl+X+WksjzVXoqQXm5UYa7y9VZQC1sP+IcNT2llgDnuzYawIDAQAB'

const privateKey = 'MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAIvut4NY0/9Oz1IP9uWR+dgmYNrZMKqZGC3yrbbehJQWmbznP2aJnYxvLQolYTZTZoIDAXq8Q5Za6+3Gng4RX8EuDghpvgtJX5gx0MAR2nl/K6sa7rYeDYCC6iCol1mX5f5aSyPNVeipBeblRhrvL1VlALWw/4hw1PaWWAOe7NhrAgMBAAECgYEAiHPBCdj96VFNg4VDyjtdufQ6sE3oUgM1++BQmylDeTDMu9N4FKIPOtlSvzkSIaqUJCWQNMIO2jhRJi1vBOLWTofraCxmWDojxn1sspjwVCEh7OKBDtz+jjPSdKddgs/xKNmEE61UVUg7uu/Q8pRzm7yU22vsfp46Zj8v2D6KGjkCQQD6IhOIDwxOWNjiwnk0lYAbQtKXxciSwNI5FPkOcAixwvKkzTgeGSSw2FF357aZIIQlc/NdruGfuCJ3rJNPsNM9AkEAjzbw78YjnrArxQW+jDZBq2GVyy5GMl5eprNxnUshn9zmkHRQXHcNP+oMg5sBpaw9yw/r8mHtM0JYX6bYp9V0xwJAErCzJuqA7+XBpwgDCIPXQ7I1jDOyLg0MaEmB5qtGawn3GYtgExer3y76v2vn//8nAKluWOS1ZTrcEHcrtruuvQJAAfXNjGqY2DYvEy5F8mNXuMHILBTBDzVtdDimiHGbzzVVzopZAzr56nMIotB/UEYwPlREdXfTqEzzKrP86ScpxwJBAPgCYj0x+jwqPFGHLaQhXofFWK9xZDPVhpp3YMHjXqr9ly+lWsK4lKC95i6rvwb/avSbwNJoVXbDPZZgetxEqdg='

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

