I encountered an issue with the 'openpgp.encrypt is not a function' error while attempting to follow the sample provided on the openpgp.js github page: https://github.com/openpgpjs/openpgpjs/blob/master/README.md#getting-started
After following the example and installing it using npm install --save openpgp
I proceeded to test the code snippets labeled 'setup' and 'Encrypt and decrypt Uint8Array data with a password'
//Set up
var openpgp = require('openpgp'); // use as CommonJS, AMD, ES6 module or through window.openpgp
openpgp.initWorker({ path:'openpgp.worker.js' }) // specify the relative web worker path
openpgp.config.aead_protect = true // enable 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: ['confidential info'], // multiple passwords allowed
armor: false // avoid ASCII armor (for Uint8Array output)
};
openpgp.encrypt(options).then(function(ciphertext) {
encrypted = ciphertext.message.packets.write(); // retrieve raw encrypted packets as Uint8Array
});
options = {
message: openpgp.message.read(encrypted), // interpret encrypted bytes
password: 'confidential info', // decrypt using password
format: 'binary' // output as Uint8Array
};
openpgp.decrypt(options).then(function(plaintext) {
return plaintext.data // Uint8Array([0x01, 0x01, 0x01])
});
This is the error message that appeared:
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