How to use the openpgp.sign function in openpgp

To help you get started, we’ve selected a few openpgp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / openpgp / openpgp-tests.ts View on Github external
(async () => {
    const publicKey = (await openpgp.key.readArmored(spubkey));
    const privateKey = (await openpgp.key.readArmored(sprivkey));
    const signOptions: openpgp.SignOptions = {
        message: openpgp.message.fromText('hello world'),
        privateKeys: privateKey.keys,
        detached: true
    };

    const signed = await openpgp.sign(signOptions);

    const signature = signed.signature as openpgp.signature.Signature;
    const message = signed.message;

    // Test function reload
    openpgp.sign({
        message: null,
        privateKeys: [],
        detached: true
    }).then(s => s.signature/* as string*/);
    openpgp.sign({
        message: null,
        privateKeys: [],
        detached: false,
    }).then(s => s.data/* as string*/);
    openpgp.sign({
github DefinitelyTyped / DefinitelyTyped / types / openpgp / ts3.2 / openpgp-tests.ts View on Github external
(async () => {
    const publicKey = (await openpgp.key.readArmored(spubkey))
    const privateKey = (await openpgp.key.readArmored(sprivkey))
    const signOptions: openpgp.SignOptions = {
        message: openpgp.message.fromText('hello world'),
        privateKeys: privateKey.keys,
        detached: true
    };

    const signed = await openpgp.sign(signOptions);

    // Test function reload
    openpgp.sign({
        message: null,
        privateKeys: [],
        detached: true
    }).then(s => s.signature/* as string*/);
    openpgp.sign({
        message: null,
        privateKeys: [],
        detached: false,
    }).then(s => s.data/* as string*/);
    openpgp.sign({
        message: null,
        privateKeys: [],
        armor: false,
github DefinitelyTyped / DefinitelyTyped / types / openpgp / openpgp-tests.ts View on Github external
privateKeys: privateKey.keys,
        detached: true
    };

    const signed = await openpgp.sign(signOptions);

    const signature = signed.signature as openpgp.signature.Signature;
    const message = signed.message;

    // Test function reload
    openpgp.sign({
        message: null,
        privateKeys: [],
        detached: true
    }).then(s => s.signature/* as string*/);
    openpgp.sign({
        message: null,
        privateKeys: [],
        detached: false,
    }).then(s => s.data/* as string*/);
    openpgp.sign({
        message: null,
        privateKeys: [],
        armor: false,
        detached: true
    }).then(s => s.signature/* as openpgp.signature.Signature*/);
    openpgp.sign({
        message: null,
        privateKeys: [],
        armor: false,
        detached: false,
    }).then(s => s.message/* as openpgp.message.Message*/);
github henryboldi / felony / pgpServer.js View on Github external
app.post('/sign', async function (req, res) {
  try {
    const privateKey = openpgp.key.readArmored(req.body.privateKeyArmored).keys[0]
    const passphrase = getPrivateKeyPassphrase(privateKey)

    const decryptedKey = await decryptPrivateKey(privateKey, passphrase)

    const options = {
      data: req.body.message,     // parse armored message
      //publicKeys: openpgp.key.readArmored(pubkey).keys,    // for verification (optional)
      privateKeys: [decryptedKey], // for decryption
    }

    const signed = await openpgp.sign(options)
    const signedMessage = signed.data

    res.send({ signedMessage })
  } catch (err) {
    console.log(err)
  }
})
github transmute-industries / transmute / packages / transmute-did / src / lib / cryptoSuites / openpgpExtensions / cryptoHelpers / index.js View on Github external
return new Promise((resolve) => {
    openpgp.sign(options).then((signed) => {
      const cleartext = signed.data; // '-----BEGIN PGP SIGNED MESSAGE ... END PGP SIGNATURE-----'
      resolve(cleartext);
    });
  });
};
github transmute-industries / transmute / packages / transmute-did / src / lib / cryptoSuites / openpgpExtensions / cryptoHelpers / index.js View on Github external
const signDetached = async (data, privateKey, passphrase) => {
  const privKeyObj = (await openpgp.key.readArmored(privateKey)).keys[0];
  await privKeyObj.decrypt(passphrase);
  const options = {
    message: openpgp.cleartext.fromText(data), // CleartextMessage or Message object
    privateKeys: [privKeyObj], // for signing
    detached: true,
  };
  const signed = await openpgp.sign(options);
  return signed.signature;
};
github airswap / AirSwap.js / src / keySpace / index.js View on Github external
async sign(text) {
    await this.setUpPGP()
    const privKeyObj = (await openpgp.key.readArmored(this.signerPGPKey.private)).keys[0]
    await privKeyObj.decrypt(this.signedSeed)
    const signedData = await openpgp
      .sign({
        message: openpgp.cleartext.fromText(text), // CleartextMessage or Message object
        privateKeys: [privKeyObj], // for signing
      })
      .then(signed => signed.data)
    return signedData
  }
  async validate(cleartext, fromAddress) {
github RedpointGames / pkgsign / src / lib / pgpSigner.ts View on Github external
public async signEntries(deterministicSignature: string): Promise {
        console.log('signing with private pgp key...');
        const privateKeyFileContents = await readFilePromise(this.privateKeyPath);
        const privateKeyObject = openpgp.key.readArmored(privateKeyFileContents).keys[0];
        privateKeyObject.decrypt(this.privateKeyPassphrase);
        const options = {
            data: deterministicSignature,
            privateKeys: privateKeyObject,
            detached: true,
        };
        const signedResult = await openpgp.sign(options);
        return signedResult.signature.replace(/\r\n/g, "\n");
    }
}
github RedpointGames / pkgsign / dist / lib / pgpSigner.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
            console.log('signing with private pgp key...');
            const privateKeyFileContents = yield fsPromise_1.readFilePromise(this.privateKeyPath);
            const privateKeyObject = openpgp.key.readArmored(privateKeyFileContents).keys[0];
            privateKeyObject.decrypt(this.privateKeyPassphrase);
            const options = {
                data: deterministicSignature,
                privateKeys: privateKeyObject,
                detached: true,
            };
            const signedResult = yield openpgp.sign(options);
            return signedResult.signature.replace(/\r\n/g, "\n");
        });
    }
github ProtonMail / WebClient / src / libraries / pmcrypto.js View on Github external
return new Promise((resolve, reject) => {

            if (privKeys === undefined || privKeys.length < 1) {
                return reject(new Error('Missing private keys'));
            }

            const options = {
                data: message,
                privateKeys: privKeys,
                armor: true
            };

            openpgp.sign(options).then((signedMsg) => {
                resolve(signedMsg.data);
            }).catch(function(err) {
                reject('Message signing failed');
            });
        });
    }