Reputation: 2856
in NodeJS:
>var md5 = require('md5')
>md5([1])
55a54008ad1ba589aa210d2629c1df41
in Ruby:
pry(main)> Digest::MD5.hexdigest [1]
TypeError: no implicit conversion of Array into String
from (pry):20:in `digest'
I am trying to use 'Array#pack' to convert a byte array to big-endian 32-bit words in:
pry(main)> Digest::MD5.hexdigest [1].pack('L*')
=> "4352d88a78aa39750bf70cd6f27bcaa5"
But result is different with nodejs, I am not familiar with byte operation, Please let me know how to use ruby to get same result with nodejs
Upvotes: 1
Views: 524
Reputation: 121010
▶ Digest::MD5.hexdigest [1].pack 'U*'
#⇒ "55a54008ad1ba589aa210d2629c1df41"
Upvotes: 1