main.js
// public key of the sender to verify signed data
public key of the sender to verify signed data
public key of the sender to verify signed data
async function decryptBinary(privkey,passphrase,pubkey,sourceFile,destFile)
{
    var privKeyObj = (await openpgp.key.readArmored(privkey)).keys[0];
    await privKeyObj.decrypt(passphrase);
    var publicKeys = (await openpgp.key.readArmored(pubkey)).keys;
    const file = fs.readFileSync(sourceFile);
    const fileForOpenpgpjs = new Uint8Array(file);
    var options;
    if(pubkey == null)
    {
        options = {
            message: await openpgp.message.read(fileForOpenpgpjs),
            format: 'binary',
            privateKeys: [privKeyObj]
        }
    }
    else
    {
        options = {
            message: await openpgp.message.read(fileForOpenpgpjs),
            format: 'binary',
            publicKeys: publicKeys,
            privateKeys: [privKeyObj]
        }
    }
    const decryptionResponse = await openpgp.decrypt(options);
    const decryptedFile = decryptionResponse.data;
    fs.writeFileSync(destFile, decryptedFile);
}
async function decryptBinary ( privkey , passphrase , pubkey , sourceFile , destFile ) { var privKeyObj = ( await openpgp . key . readArmored ( privkey ) ) . keys [ 0 ] ; await privKeyObj . decrypt ( passphrase ) ; var publicKeys = ( await openpgp . key . readArmored ( pubkey ) ) . keys ; const file = fs . readFileSync ( sourceFile ) ; const fileForOpenpgpjs = new Uint8Array ( file ) ; var options ; if ( pubkey == null ) { options = { message : await openpgp . message . read ( fileForOpenpgpjs ) , format : 'binary' , privateKeys : [ privKeyObj ] } } else { options = { message : await openpgp . message . read ( fileForOpenpgpjs ) , format : 'binary' , publicKeys : publicKeys , privateKeys : [ privKeyObj ] } } const decryptionResponse = await openpgp . decrypt ( options ) ; const decryptedFile = decryptionResponse . data ; fs . writeFileSync ( destFile , decryptedFile ) ; }
public key of the sender to verify signed data
public key of the sender to verify signed data
//publicKeys: publicKeys, //const unzip = require('unzip'); // var iStream=fs.createReadStream(destFile); // iStream.pipe(unzip.Extract({path: destFile.slice(0,-4)})); //const decrypted = await openpgp.decrypt(options); //const plaintext = await openpgp.stream.readToEnd(decrypted.data); // var plaintext = await openpgp.stream.readToEnd(decrypted.data); //var wstream = fs.createWriteStream(filePath) //wstream.write(plaintext) //wstream.close() //await openpgp.stream.pipe(decrypted.data,wstream) //fs.writeFileSync(filePath,plaintext); //return plaintext; // return(plaintext);