0
我得到“openpgp.encrypt不是一个函数”的错误,而试图在openpgp.js GitHub的页面给出的示例:https://github.com/openpgpjs/openpgpjs/blob/master/README.md#getting-started错误:“openpgp.encrypt不是一个函数”
继的例子给出,并与npm install --save openpgp
安装后我然后试图摘录标记为“设置”和“加密和用密码解密Uint8Array数据”
// Set up
var openpgp = require('openpgp'); // use as CommonJS, AMD, ES6 module or via window.openpgp
openpgp.initWorker({ path:'openpgp.worker.js' }) // set the relative web worker path
openpgp.config.aead_protect = true // activate fast AES-GCM mode (not yet OpenPGP standard)
// Encrypt and decrypt Uint8Array data with a password
var options, encrypted;
options = {
data: new Uint8Array([0x01, 0x01, 0x01]), // input as Uint8Array (or String)
passwords: ['secret stuff'], // multiple passwords possible
armor: false // don't ASCII armor (for Uint8Array output)
};
openpgp.encrypt(options).then(function(ciphertext) {
encrypted = ciphertext.message.packets.write(); // get raw encrypted packets as Uint8Array
});
options = {
message: openpgp.message.read(encrypted), // parse encrypted bytes
password: 'secret stuff', // decrypt with password
format: 'binary' // output as Uint8Array
};
openpgp.decrypt(options).then(function(plaintext) {
return plaintext.data // Uint8Array([0x01, 0x01, 0x01])
});
以下是错误:
TypeError: openpgp.encrypt is not a function
at Object.<anonymous> (/home/tgrego/1/Src/Example/Javascript/Node.js/OpenPgp/openpgpExamp.js:20:9)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3
在调试器检查OpenPGP的显示.encryptMessage是OpenPGP的的方法,但不是。加密。然而,用encryptMessage代替加密来尝试代码仍然失败。 – tgoneil
也许这更适合作为GitHub上的问题。在我看来,像有人忘记在代码摆弄之后更新文档。 –
谢谢Artjom。我刚刚在GitHub存储库中提交了这个问题。 – tgoneil