var publicKey = `-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDM/Mywbt4Nq8UiT7cxpco0lty8ATU7uilUY6d3RWY7+LUmfEBtSSwLYCiUdSS9iQHsnYNrxSQ0SWt8/p+EhSC/RIudzUtkGi/ylRYLVwaYE7ehyjBw+un/oyDievlWMxlWYibGxC4DFEJu4LM3A0Q+TzNmRllwJToAB5JUShNV0wIDAQAB-----END PUBLIC KEY-----`;//自己拼接头跟尾 var encrypt = new JSEncrypt(); encrypt.setPublicKey(publicKey); var en = encrypt.encrypt("欢迎来到chacuo.net") // 加密 console.log(en);