Monday 12 June 2017

How do I decrypt an AES256 bit cipher in golang that was encrypted in nodejs?

I encrypted a string in Node.js like this.

var cipher = crypto.createCipheriv(
"aes256",
"<A Buffer of length 32>",
"79b67e539e7fcaefa7abf167de5c06ed"  
);

I noticed that a buffer in nodejs is like hex but every 2 consecutive characters are paired. So, It's length is half of whatever will come out if I convert it to a hex.

Example:

Buffer:

<Buffer c3 80 36 f6 51 57 cb 6d b0 e8 fd 85 5a a2 8a da 07 4b e7 19 17 d1 c8 ee dc 2a e4 d8 5e 3c 9d a6>

Hex:

c38036f65157cb6db0e8fd855aa28ada074be71917d1c8eedc2ae4d85e3c9da6

Now, The key I use in aes256 can not be of length 64. Here, Buffer's length is 32 and hex's length is 64.

I want to decrypt this cipher in golang and I'll have to use this key and iv to decrypt it.

aes in golang takes a length depending upon the size of key and when it sees a key of length 64 it throws an error that says, Invalid key length.

How do I decrypt it in golang?



via Ishan Jain

No comments:

Post a Comment