Skip to content
Advertisement

Create a Random AES Key in JS that can transferred to PHP?

I have a form processing script that uses AES and RSA Encryption together.

At first, I solely used RSA but because of the data limit, I have started using AES encryption whose keys are now encrypted with RSA.

I have made sure that I can decrypt the AES if I generate a random string by hand but when I use

var key = forge.random.getBytesSync(32);
var iv = forge.random.getBytesSync(32);

I can not transfer it to PHP. When I used PHPAES library, an exception is thrown, complaining that my key size is incorrect.

How can I create Cryptographically Secure Keys that I can also transfer into PHP?

If any more information is needed, I am eager to provide it.

Advertisement

Answer

Kudos to @MichaelFehr,

I have fixed it. The problem was with the length of the IV.

var key = forge.random.getBytesSync(32);
var iv = forge.random.getBytesSync(16); // not 32

This works!

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement