const openpgp = require('openpgp');

const fs = require("fs");

var privateKeyArmored = "";
var publicKeyArmored = "";
const passphrase = `123456`;

const encryptedAndSignedMessage = ``;

loadPGP();

(async () => {
    const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });

    const privateKey = await openpgp.decryptKey({
        privateKey: await openpgp.readKey({ armoredKey: privateKeyArmored }),
        passphrase
    });

    const encrypted = await openpgp.encrypt({
        message: await openpgp.createMessage({ text: 'Hello, World!' }), // input as Message object
        publicKeys: publicKey, // for encryption
        privateKeys: privateKey // for signing (optional)
    });
    console.log(encrypted); // 'Hello, World!'
})();


async function loadFile(fileName) {
    var dataEncrypt = "";
    try {
      dataEncrypt = fs.readFileSync(fileName, 'utf8')
      console.log("Data Encrypt: " + dataEncrypt);
    } catch (err) {
      console.error(err)
    }
    return dataEncrypt;
    console.log("Load data successfully!!!");
}

async function loadPGP() {
    privateKeyArmored = fs.readFileSync('partner-sec.asc', 'utf8');
    publicKeyArmored = fs.readFileSync('mservice-pub.asc', 'utf8');
    console.log("Load PGP key successfully!!!");
}
