I'm using openpgp.js in my chrome extension, and sendResponse
that sends the response to the content script from decryptMessage
is NOT working:
openpgp.decryptMessage(key, message).then(function(plaintext) {
var res = sendResponse({result: "test"});
})
But it works inside the encryptMessage
function:
openpgp.encryptMessage(publicKey.keys, base64Message).then(function(pgpMessage) {
sendResponse({result: pgpMessage});
})
In the background console there are no errors, I have no clues why this is happening.
The entire onMessage
handler:
function handleMessageEvent(request, sender, sendResponse) {
console.log('just-encrypt');
if(request.data.type == 'decrypt')
{
var key = openpgp.key.readArmored(request.data.privateKey);
console.log(key);
if(key.keys.length > 0)
{
key = key.keys[0];
key.decrypt(request.data.password);
var message = openpgp.message.readArmored(request.data.message);
console.log('decrypt message');
openpgp.decryptMessage(key, message).then(function(plaintext) {
console.log('decrypted');
sendResponse({result: 'test'});
}).catch(function(error) {
console.log(error);
});
}
else
{
chrome.extension.getBackgroundPage().console.log("no accessible keys found");
}
return true;
}