1. const fs=require('fs');
  2. const crypto=require('crypto');
  3. const privateKey=fs.readFileSync('8000013189_pri.pem','utf-8');
  4. console.log(privateKey);
  5. function encrypt(stuff) {
  6. let encryptString = Buffer.from(Buffer.from(stuff).toString('base64'));
  7. let result ='';
  8. while (encryptString.length > 117) {
  9. const chunk = encryptString.slice(0, 117);
  10. encryptString = encryptString.slice(117);
  11. result += crypto.privateEncrypt(privateKey, chunk).toString('hex');
  12. }
  13. result += crypto.privateEncrypt(privateKey, encryptString).toString('hex');
  14. return result;
  15. }
  16. console.log(encrypt("123456"));
文档更新时间: 2019-06-17 11:21   作者:support