Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
openpgp.message.readArmored(pgpMessageStr).then((pgpMessage) => {
const options = {
message: pgpMessage
};
return openpgp.decrypt(options);
}).then((plaintext) => {
// success
if ({}.isPrototypeOf.call(Uint8Array.prototype, privateKey)) {
options.sessionKey = { data: privateKey, algorithm: sessionKeyAlgorithm };
} else if (typeof privateKey === 'string' || privateKey instanceof String) {
options.password = privateKey;
} else {
options.privateKey = privateKey;
}
if (binary) {
options.format = 'binary';
}
let sig;
try {
openpgp.decrypt(options).then((decrypted) => {
// for now, log signature info in console - later integrate with front end
if (binary) {
if (decrypted.signatures == null || decrypted.signatures[0] == null) {
if (config.debug) {
console.log('No attachment signature present or no public keys provided');
}
sig = 0;
} else if (decrypted.signatures[0].valid) {
if (config.debug) {
console.log('Verified attachment signature');
}
sig = 1;
} else {
if (config.debug) {
console.log('Attachment signature could not be verified');
}
receiveMessage(payload) {
let tags = this.state.tagOptions;
let postMessage = false;
payload.tags.forEach((t) => {
tags = tags.includes(t) ? tags : tags.concat([t]);
postMessage = postMessage || this.state.tags.includes(t);
});
if (this.state.tags.length === 0 || postMessage) {
const currentMessage = this.props.messageReducer.messages[payload.id]
if (!currentMessage) {
this.privKeyObj = this.privKeyObj || openpgp.key.readArmored(this.props.cryptoReducer.groups[this.room].privateKey).keys[0];
const options = {
message: openpgp.message.readArmored(payload.text), // parse armored message
privateKeys: [this.privKeyObj] // for decryption
};
openpgp.decrypt(options).then((plaintext) => {
const newMessage = {id: payload.id, name: payload.name, text: plaintext.data, color: payload.color, timestamp: moment().format(), tags: payload.tags, uuid: payload.uuid }
this.props.addMessage(newMessage);
this.addMessage(newMessage, payload, tags)
});
} else {
this.addMessage(currentMessage, payload, tags)
}
}
}
function getPrivateKeyCallback(items) {
var privateKey = openpgp.key.readArmored(items.privateKey).keys[0];
privateKey.decrypt(__passphrase);
var pgpMessage = openpgp.message.readArmored(data.response);
openpgp
.decrypt({
message: pgpMessage,
privateKey: privateKey,
})
.then(function onSuccess(plaintext) {
// success!
// read only the first line as the password
var eol = plaintext.data.indexOf('\n');
if (eol !== -1) {
plaintext.data = plaintext.data.slice(0, eol);
}
done({password: plaintext.data});
})
.catch(function onError(error) {
(async () => {
let cipher = await openpgp.encrypt({
message: openpgp.message.fromText('hello world'),
passwords: 'super secure',
armor: true,
});
let encrypted = cipher.data;
let plain = await openpgp.decrypt({
message: await openpgp.message.readArmored(encrypted),
passwords: 'super secure',
});
return plain.data;
})();
export async function decryptoMessage ( openKeyOption, message: string, CallBack ) {
const option = {
privateKeys: openKeyOption.privateKeys,
publicKeys: openKeyOption.publicKeys,
message: null
}
option.message = await OpenPgp.message.readArmored ( message )
return OpenPgp.decrypt ( option ).then ( async data => {
/**
* verify signatures
*/
await data.signatures[0].verified
//console.log ( Util.inspect ( data, false, 3, true ))
if ( data.signatures[0].verified ) {
return CallBack ( null, data.data )
}
return CallBack ( new Error ('signatures error!'))
}).catch ( err => {
console.trace ( err )
export async function decrypt(encryptedMessage, privateKeyArmored) {
const encryptedMessageMassaged = massagePGP(encryptedMessage)
const privateKey = openpgp.key.readArmored(privateKeyArmored).keys[0]
const passphrase = getPrivateKeyPassphrase(privateKey)
privateKey.decrypt(passphrase)
const options = {
message: openpgp.message.readArmored(encryptedMessageMassaged),
privateKey,
}
const plaintext = await openpgp.decrypt(options)
return plaintext.data
}
async decryptSyncMessage(encrypted: {
message: string
nonce?: string
}): Promise {
if (!this.key) {
throw new Error('Tried to decrypt sync message without a key')
}
return (await openpgp.decrypt({
message: await openpgp.message.readArmored(encrypted.message),
passwords: [this.key],
format: 'utf8',
})).data as string
}
privKeyObj.decrypt(state.cryptoReducer.passphrase).then(() => {
const options = {
message: openpgp.message.readArmored(encryptedPrivateKey),
privateKeys: [privKeyObj]
};
openpgp.decrypt(options).then((plaintext) => {
dispatch({
type: 'new_group_key',
privateKey: plaintext.data,
publicKey,
room,
name
});
const groupPrivateKey = openpgp.key.readArmored(plaintext.data).keys[0];
users.forEach((user) => {
if (user.avatar) {
const groupOptions = {
privateKeys: [groupPrivateKey],
message: openpgp.message.readArmored(user.avatar)
}
openpgp.decrypt(groupOptions).then((plaintext) => {
const addUser = {