How to decrypt base64 string from NodeJs encrypted?

Hi everyone,

I’m try encrypt message by NodeJs, and convert to base64,
after send to Elixir server with WebSocket,
trying to decrypt from base64 string,
but i never success…

and i’m trying compare both side encrypt result,
it’s have alot different…

here is my testing code…

NodeJs part…

var crypto = require( 'crypto' );
var key = '0000000000000000';
var value = 'test';
var cipher = crypto.createCipher('rc4', key );
var encoded = cipher.update( value, 'utf8', 'base64');
encoded += cipher.final( 'base64' );

console.info( 'Result[' + encoded + ']' );
//Result[sFvlow==]

Elixir part…


key = "0000000000000000"
value = "test"
{ _, r } = :crypto.stream_init(:rc4, key ) |> :crypto.stream_encrypt( value )
result = Base.encode64( r )
IO.puts "Result[#{ result }]"
#Result[/BrV9A==]

anyone can help me, please :slight_smile:

Sorry for my english,
Thanks

According to http://rc4.online-domain-tools.com/ using your key and input, it outputs: fc 1a d5 f4

What your javascript code puts out for the encoded value: B0 5B E5 A3

What your Elixir code puts out for the encoded value: FC 1A D5 F4

So it looks like it is correct in Elixir and wrong in your javascript code, thus implying that the code generating it in Javascript is wrong. :slight_smile:

1 Like

Oh my god, @OvermindDL1 Thank you Very Very Much :joy:

your advice lead me found the solution,

i use this code …
the both side had correct base64 string.


var crypto = require( 'crypto' );
var key = '0000000000000000';
    key = require( 'crypto-js' ).enc.Utf8.parse( key ); //add this to convert key
var value = 'test';
var cipher = crypto.createCipher('rc4', key );
var encoded = cipher.update( value, 'utf8', 'base64');
encoded += cipher.final( 'base64' );

console.info( 'Result[' + encoded + ']' );
//Result[/BrV9A==]

i don’t really know why about the this,
but problem is resolve,
Thank you so so much :smiley:

1 Like

Awesome! Thanks for the follow-up, I honestly had no clue ‘why’ the javascript version was not working so it is awesome to see the working code. :smiley:

1 Like