Reputation: 6129
How do I convert a hash string originally encoded with Digest::MD5.digest('abc')
to a hex string in the following format Digest::MD5.hexdigest('abc')
? The difference is that the hex string is safe against different encoding issues (regardless of the encoding it is read in).
Upvotes: 3
Views: 1783
Reputation: 27793
Try this
string = Digest::MD5.digest('abc')
Digest.hexencode(string)
Upvotes: 0
Reputation: 6129
Using then unpack method will do the trick. (Checkout the official documentation)
Digest::MD5.digest('http://www.example.com').unpack('H*').first == Digest::MD5.hexdigest('http://www.example.com')
Upvotes: 3