Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const encryptMessage = async ({
message, privateKey, publicKey, passphrase,
}) => {
const privKeyObj = (await openpgp.key.readArmored(privateKey)).keys[0];
await privKeyObj.decrypt(passphrase);
const options = {
message: openpgp.message.fromText(message), // input as String (or Uint8Array)
publicKeys: (await openpgp.key.readArmored(publicKey)).keys, // for encryption
privateKeys: [privKeyObj], // for signing (optional)
};
return openpgp.encrypt(options).then((ciphertext) => {
const encrypted = ciphertext.data; // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
return encrypted;
});
};
export const encryptMessage = ( openKeyOption, message: string, CallBack ) => {
const option = {
privateKeys: openKeyOption.privateKeys,
publicKeys: openKeyOption.publicKeys,
data: message
}
//console.log (`encryptMessage `, message )
return OpenPgp.encrypt ( option ).then ( ciphertext => {
return CallBack ( null, ciphertext.data )
}).catch ( CallBack )
}
exports.encryptMessage = (openKeyOption, message, CallBack) => {
const option = {
privateKeys: openKeyOption.privateKeys,
publicKeys: openKeyOption.publicKeys,
data: message
};
//console.log (`encryptMessage `, message )
return OpenPgp.encrypt(option).then(ciphertext => {
return CallBack(null, ciphertext.data);
}).catch(CallBack);
};
exports.decryptoMessage = (openKeyOption, message, CallBack) => {
}).catch(function(err) {
if (privKeys) {
options.privateKeys = [];
}
openpgp.encrypt(options).then((ciphertext) => {
resolve(ciphertext.data);
});
});
});
return options.privateKeys[0].decrypt ( data.toString( 'hex' )).then ( keyOK => {
return OpenPgp.encrypt ( options ).then ( ciphertext => {
return Fs.writeFile ( fileName, ciphertext.data, { encoding: 'utf8' }, CallBack )
}).catch ( CallBack )
}).catch ( CallBack )
hkp.lookup(findOptions).then(function(pubkey) {
let encryptOptions = {
data: record,
publicKeys: openpgp.key.readArmored(pubkey).keys
};
openpgp.encrypt(encryptOptions).then(function(ciphertext) {
return dispatch(doTransfer(values.guardian, 0.0001, ciphertext.data));
});
});
} else {
async consumeClaim() {
const userPublicKey = openpgp.key.readArmored(this.props.cryptoReducer.publicKey).keys
const options = {
data: this.props.cryptoReducer.groups[this.room].privateKey,
publicKeys: userPublicKey
};
const encryptObject = await openpgp.encrypt(options)
this.channel.push("consume_claim", {publicKey: this.props.cryptoReducer.publicKey, teamPublicKey: this.props.cryptoReducer.groups[this.room].publicKey, encryptedTeamPrivateKey: encryptObject.data})
this.pushNewTags(this.state.tags);
this.setState({
...this.state,
generatingGroupKey: false
})
}
return options.privateKeys[0].decrypt(data.toString('hex')).then(keyOK => {
return OpenPgp.encrypt(options).then(ciphertext => {
return Fs.writeFile(fileName, ciphertext.data, { encoding: 'utf8' }, CallBack);
}).catch(CallBack);
}).catch(CallBack);
});
approveRequest(e) {
e.preventDefault();
const data = e.target.dataset;
const options = {
data: this.props.cryptoReducer.groups[this.room].privateKey,
publicKeys: openpgp.key.readArmored(data.publicKey).keys
};
openpgp.encrypt(options).then((ciphertext) => {
const encrypted = ciphertext.data;
this.channel.push("approve_request", { uuid: data.uuid, groupPublicKey: this.props.cryptoReducer.groups[this.room].publicKey, encryptedGroupPrivateKey: encrypted})
});
}