-
npm install node-rsa
var pub: string = `公钥字符串`; var pri: string = `私钥字符串`; const NodeRSA = require('node-rsa'); // 初始化密钥 var pubKey = new NodeRSA(pub, 'pkcs8-public'); var priKey = new NodeRSA(pri, 'pkcs8-private') // 公钥加密 const text = 'Hello RSA!'; const encrypted = pubKey.encrypt(text, 'base64'); console.log('encrypted: ', encrypted); // 私钥解密 const decrypted = priKey.decrypt(encrypted, 'utf8'); console.log('decrypted: ', decrypted);
Node.js RSA加密库使用笔记
最新推荐文章于 2024-08-06 10:40:11 发布