Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(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({
(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,
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*/);
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)
}
})
return new Promise((resolve) => {
openpgp.sign(options).then((signed) => {
const cleartext = signed.data; // '-----BEGIN PGP SIGNED MESSAGE ... END PGP SIGNATURE-----'
resolve(cleartext);
});
});
};
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;
};
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) {
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");
}
}
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");
});
}
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');
});
});
}