1、生成 private key
openssl genrsa -out rsa_1024_priv.pem 1024
2、生成public key
openssl rsa -pubout -in rsa_1024_priv.pem -out rsa_1024_pub.pem
3、根据public key对数据加密
let encrypt = new JSEncrypt(); encrypt.setPublicKey(__YOU_CREATE_PUBLIC_KEY__); let encrypted = encrypt.encrypt(__YOU_ENCRYPT_DATA__);
4、根据private key对加密数据解密
let decrypt = new JSEncrypt(); decrypt.setPrivateKey(__YOU_CREATE_PRIVATE_KEY___); let uncrypted = decrypt.decrypt(__YOU_ENCRYPTED_DATA__);