Discuss / JavaScript / 求解疑,实在找遍网上没有办法

求解疑,实在找遍网上没有办法

Topic source

#1 Created at ... [Delete] [Delete and Lock User]
const
    fs = require('fs'),
    crypto = require('crypto');

// 从文件加载key:
function loadKey(file) {
    // key实际上就是PEM编码的字符串:
    return fs.readFileSync(file, 'utf8');
}

let
    prvKey = loadKey('./rsa-prv.pem'),
    pubKey = loadKey('./rsa-pub.pem'),
    message = 'Hello, world!';

// 使用私钥加密:
let enc_by_prv = crypto.privateEncrypt(prvKey, Buffer.from(message,'utf8'));
console.log('encrypted by private key: ' + enc_by_prv.toString('hex'));


let dec_by_pub = crypto.publicDecrypt(pubKey, enc_by_prv);
console.log('decrypted by public key: ' + dec_by_pub.toString('utf8'));

运行报错:

Uncaught Error Error: error:25078067:DSO support routines:win32_load:could not load the shared library at <anonymous> (node:internal/crypto/cipher:79:12) at <anonymous> (e:\编程\HBuilderX\HBuilderX code\Node.js\study\crypto\RSA.js:17:25) at Module._compile (node:internal/modules/cjs/loader:1105:14) at Module._extensions..js (node:internal/modules/cjs/loader:1159:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Module._load (node:internal/modules/cjs/loader:822:12) at executeUserEntryPoint (node:internal/modules/run_main:77:12) at <anonymous> (node:internal/main/run_main_module:17:47)

#2 Created at ... [Delete] [Delete and Lock User]

Uncaught Error Error: error:25078067:DSO support routines:win32_load:could not load the shared library 

 at <anonymous> (node:internal/crypto/cipher:79:12) 

 at <anonymous> (e:\编程\HBuilderX\HBuilderX code\Node.js\study\crypto\RSA.js:17:25) 

 at Module._compile (node:internal/modules/cjs/loader:1105:14) 

 at Module._extensions..js (node:internal/modules/cjs/loader:1159:10) 

 at Module.load (node:internal/modules/cjs/loader:981:32) 

 at Module._load (node:internal/modules/cjs/loader:822:12) 

 at executeUserEntryPoint (node:internal/modules/run_main:77:12) 

 at <anonymous> (node:internal/main/run_main_module:17:47)

Evan

#3 Created at ... [Delete] [Delete and Lock User]

不要使用中文文件路径


  • 1

Reply