1

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

1 Answer 1

1
 ▶ Digest::MD5.hexdigest [1].pack 'U*'
 #⇒ "55a54008ad1ba589aa210d2629c1df41"
Sign up to request clarification or add additional context in comments.

3 Comments

thanks for your reply, but result different when array contain multiple elements, like [1,2,3]
Different means what? Your question is not marked with node and I have no idea how this piece of code treats md5-ing arrays of integers. Anyway, corrected my answer, please check.
thank you, [1].pack 'U+' is right, but [1].pack 'U+' and [1,2,3].pack 'U+' are same result, the result should be different when byte array different

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.