前端RSA加密

使用jsencrypt

import { JSEncrypt } from "jsencrypt";

/**
 *
 * @param {文本值} value
 * @param {公钥} publicKey
 */
function encryptPublic(value, publicKey) {
  // 使用公钥加密,default_key_size可为512,1024,2048等
  let encrypt = new JSEncrypt({ default_key_size: 2048 });
  encrypt.setPublicKey(publicKey);
  let encrypted = encrypt.encrypt(value);
  return encrypted;
}

详细可见 https://github.com/travist/jsencrypt

posted @ 2020-01-07 19:52  wayne529  阅读(1274)  评论(0编辑  收藏  举报