Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise(async (resolve, reject) => {
openpgp
.decrypt({
message: await openpgp.message.readArmored(encryptedMessage),
publicKeys: (await openpgp.key.readArmored(publicKeyArmored)).keys, // for verification (optional)
privateKeys: [privKeyObj],
})
.then(plaintext => {
resolve(plaintext.data)
})
.catch(reject)
})
}
.then(function (publicKey) {
return {
message: openpgp.message.fromText('Hello, World!'),
publicKeys: publicKey.keys
};
})
.then(openpgp.encrypt)
export const deCryptoWithKey1 = ( data: string, publicKey: string, privateKey: string, password: string, CallBack ) => {
let _return = false
const options: any = {
message: openpgp.message.readArmored ( data ),
publicKeys: openpgp.key.readArmored ( publicKey ).keys,
privateKey: openpgp.key.readArmored ( privateKey ).keys[0]
}
if ( ! options.privateKey.decrypt ( password )) {
return CallBack ( new Error ('saveImapData key password error!' ))
}
openpgp.decrypt ( options ).then ( plaintext => {
_return = true
return CallBack ( null, plaintext.data )
}).catch ( err => {
console.log ( data )
console.log ( err )
if ( !_return ) {
return CallBack ( err )
}
function decrypt(cipher: string): Promise {
if (isEmpty(cipher)) {
debug('empty cipher!');
return Promise.reject(new Error('EMPTY_CIPHER'));
}
if (!privateKey) {
return Promise.reject(new Error('NO_KEYS'));
}
let message: openpgp.message.Message;
try {
message = openpgp.message.readArmored(cipher);
} catch (err) {
debug('READ_ARMORED_FAILED', err.message);
return Promise.reject(err);
}
return openpgp.decrypt({ privateKey, message })
.then(({ data }) => data as string);
}
const attemptVerify = async (rawPublicKeys: string) => {
try {
const publicKeys = (await openpgp.key.readArmored(rawPublicKeys)).keys;
const verifyOptions = {
message: openpgp.message.fromText(deterministicString),
signature: await openpgp.signature.readArmored(signature),
publicKeys: publicKeys
};
const verifiedMessage = await openpgp.verify(verifyOptions);
return verifiedMessage.signatures.length >= 1;
} catch (e) {
return false;
}
};
const attemptVerify = async (rawPublicKeys: string) => {
try {
const publicKeys = (await openpgp.key.readArmored(rawPublicKeys)).keys;
const verifyOptions = {
message: openpgp.message.fromText(deterministicString),
signature: await openpgp.signature.readArmored(signature),
publicKeys: publicKeys
};
const verifiedMessage = await openpgp.verify(verifyOptions);
return verifiedMessage.signatures.length >= 1;
} catch (e) {
return false;
}
};
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)
return async (dispatch, getState) => {
const state = getState();
var privKeyObj = openpgp.key.readArmored(state.cryptoReducer.privateKey).keys[0];
await privKeyObj.decrypt(state.cryptoReducer.passphrase)
const privateKeyOptions = {
message: openpgp.message.readArmored(encryptedPrivateKey),
privateKeys: [privKeyObj]
};
const privateKey = await openpgp.decrypt(privateKeyOptions)
const passphraseOptions = {
message: openpgp.message.readArmored(encryptedPassphrase),
privateKeys: [privKeyObj]
};
const passphrase = await openpgp.decrypt(passphraseOptions)
const newPrivateKey = privateKey.data
const newPassphrase = passphrase.data
dispatch({
type: 'new_key',
publicKey,
privateKey: newPrivateKey,
passphrase: newPassphrase
})
privKeyObj = openpgp.key.readArmored(newPrivateKey).keys[0];
await privKeyObj.decrypt(newPassphrase)
requests.requests.forEach(async (request) => {
const privateGroupKeyOptions = {
message: openpgp.message.readArmored(request.encrypted_team_private_key),
async decryptMessageBody(message: any): Promise {
try {
const messageBody = await openpgp.decrypt({
message: openpgp.message.readArmored(message.Body),
privateKey: this._privateKey
});
message.BodyDecrypted = messageBody.data;
} catch (err) {}
return message;
}
}
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
}