AES encryption in Javascript - trying to match openpgp and cryptoJS : Unexpected end of packet

94 views Asked by At

I am just trying to match up a simple AES encryption done with CryptoJS with that done with openPGP, both in Javascript:

// encrypt with CryptoJS
var ciphertext = AES.encrypt("my message", "secret key 123");

// decrypt with openPGP
const opgpencryptedMessage = await readMessage({
    binaryMessage: Uint8Array.from(Buffer.from(ciphertext.toString(format.Hex), "hex")), // parse encrypted bytes
});
const { data: decrypted_opgp } = await decrypt({
        message: opgpencryptedMessage,
        passwords: ["secret key 123"], // decrypt with password
        format: "binary", // output as Uint8Array
});

console.log("decrypted opgp:", decrypted_opgp); 

Unfortunately this doesn't work, and on decryption I get an "unexpected end of packet" error. Looking at the size of the arrays that openpgp gives me if i encrypt the same thing with that, it is much longer.. so i'm guessing it is doing some kind of padding? But I can't find any documentation on that anywhere.. and i've tried cycling through the options in cryptoJS and none of them worked.

Can anyone help with getting these things matching?

0

There are 0 answers