main.js
// public key of the recipient used to encrypt the data
public key of the recipient used to encrypt the data
public key of the recipient used to encrypt the data
async function encryptBinary(privkey,passphrase,pubkey, sourcePath) {
    var privKeyObj = (await openpgp.key.readArmored(privkey)).keys[0];
    var publicKeys = (await openpgp.key.readArmored(pubkey)).keys;
    await privKeyObj.decrypt(passphrase)
    const file = fs.readFileSync(sourcePath);
    const fileForOpenpgpjs = new Uint8Array(file);
    const options = {
        message :  openpgp.message.fromBinary(file),
        publicKeys: publicKeys,
        privateKey: privKeyObj,
        armor: false
    };
    const encryptionResponse = await openpgp.encrypt(options); 
    const encryptedFile = encryptionResponse.message.packets.write();
    var ret = {
        name : sourcePath,
        stream : encryptedFile
    }
   return ret;
}
async function encryptBinary ( privkey , passphrase , pubkey , sourcePath ) { var privKeyObj = ( await openpgp . key . readArmored ( privkey ) ) . keys [ 0 ] ; var publicKeys = ( await openpgp . key . readArmored ( pubkey ) ) . keys ; await privKeyObj . decrypt ( passphrase ) const file = fs . readFileSync ( sourcePath ) ; const fileForOpenpgpjs = new Uint8Array ( file ) ; const options = { message : openpgp . message . fromBinary ( file ) , publicKeys : publicKeys , privateKey : privKeyObj , armor : false } ; const encryptionResponse = await openpgp . encrypt ( options ) ; const encryptedFile = encryptionResponse . message . packets . write ( ) ; var ret = { name : sourcePath , stream : encryptedFile } return ret ; }
public key of the recipient used to encrypt the data
public key of the recipient used to encrypt the data
//async function encryptBinary(privkey,passphrase,pubkey, sourcePath) { //openpgp.readArmored(pubkey); // note the await here - this is async //fs.writeFileSync(destinationPath, encryptedFile); //return encryptedFile;