// import { JSEncrypt } from 'JSEncrypt'
import JSEncrypt from '@/node_modules/jsencrypt/bin/jsencrypt.js'


// 密钥对生成 http://web.chacuo.net/netrsakeypair
const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdHnzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=='
// 前端不建议存放私钥 不建议解密数据 因为都是透明的意义不大
const privateKey = 'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAmc3CuPiGL/LcIIm7zryCEIbl1SPzBkr75E2VMtxegyZ1lYRD+7TZGAPkvIsBcaMs6Nsy0L78n2qh+lIZMpLH8wIDAQABAkEAk82Mhz0tlv6IVCyIcw/s3f0E+WLmtPFyR9/WtV3Y5aaejUkU60JpX4m5xNR2VaqOLTZAYjW8Wy0aXr3zYIhhQQIhAMfqR9oFdYw1J9SsNc+CrhugAvKTi0+BF6VoL6psWhvbAiEAxPPNTmrkmrXwdm/pQQu3UOQmc2vCZ5tiKpW10CgJi8kCIFGkL6utxw93Ncj4exE/gPLvKcT+1Emnoox+O9kRXss5AiAMtYLJDaLEzPrAWcZeeSgSIzbL+ecokmFKSDDcRske6QIgSMkHedwND1olF8vlKsJUGK3BcdtM8w4Xq7BpSBwsloE='

// 加密
export const encrypt = (txt) => {
  const encrypt = new JSEncrypt()
  encrypt.setPublicKey(publicKey) // 设置公钥
  return encrypt.encrypt(txt) // 对数据进行加密
}

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