Search code examples
javascriptjavaaesforge

How to transfer aes key from js to java server?


I am trying to transfer AES key generate in js:

var AESkey = forge.random.getBytesSync(16);

exapmle if printed condsole i have "§½­üå8bdÈP"

but printed in my java server it is "—§‡½­\u001eüå8b\u000ed�\u0012P›" (other data are ok)

I tried to get the bytes with Buffer.from(AESkey) but instead of getting a 16 bytes buffer I get a 22/24/25.. buffer lenghts.

In which format can I transfer the key and how can I get my AESkey to that format in js?


Solution

  • A possible solution:

    • make a base64 encoded string on client side
    • send base64-encoded string to server
    • decode base64 in Java to get the byte sequence back

    This way the byte sequence can be safely transported.