1

the problem is that when decoding an image for example, I get a corrupted binary data, I've tried to convert it to base64, but it is invalid to display, is there a solution to decrypt pgp encrypted images valid

I am using this library, tell me it is valid for decrypting binary? http://openpgpjs.org/

ENCRYPT:

var key = request.data.publicKey;
var publicKey = openpgp.key.readArmored(key);
var base64Message = request.data.message;//btoa(request.data.message); // encoding binary data directly
openpgp.encryptMessage(publicKey.keys, base64Message).then(function(pgpMessage) {
    console.log('encrypted');
    console.log(pgpMessage);
    sendResponse({result: pgpMessage});
}).catch(function(error) {
    console.log(error);
});

DECRYPTING:

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); // error can't read pgp encoded binary data

    openpgp.decryptMessage(key,message).then(function(plaintext) {
        //do stuff...plaintext - is binary data in text
    });
}

I encode binary directly, and then trying to decode but I get an error that:

Unknown ASCII armor type

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
user3112115
  • 695
  • 3
  • 12
  • 23
  • @ArtjomB.using this library there are examples of encrypt/decrypt http://openpgpjs.org/ – user3112115 Nov 06 '15 at 11:41
  • You need to add the code that you personally used to encrypt the image that you now can't decrypt. If you are running this in a browser and want to display the image as base64, you should convert it to base64 before you encrypt it. Then when it's decrypted it will be ready to use. – Dan Prince Nov 06 '15 at 11:48
  • @DanPrince hey look I've added examples of how I encode binary directly, and then trying to decode but I get an error that: Unknown ASCII armor type – user3112115 Nov 06 '15 at 12:03

1 Answers1

0

Base 64 is used to wrap bytes into an ASCII armor so you can transport the binary data over a text oriented interface. What you need to transport is the ciphertext that seems to be written to pgpMessage. You should base 64 encode the ciphertext in there, you should not base 64 encode the plaintext message.

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263