lokheart
lokheart

Reputation: 24675

different md5 hash value for same string in R

I try to generate a md5 hash for a string using the digest package in R:

> digest::digest('testing',algo='md5')
[1] "06af8dac40480b40834f70a0fa7b35a3"

I go to http://www.md5.cz/ and do the same thing again, but the output is ae2b1fca515949e5d54fb22b8ed95575 instead.

What have I done wrong here?

Upvotes: 4

Views: 2058

Answers (1)

Maarten Bodewes
Maarten Bodewes

Reputation: 93988

As jdharrison already proposed you should set serialize to FALSE. Otherwise the serialization will add input to the hash function, making it fail:

The format consists of a single line followed by the data: the first line contains a single character: X for binary serialization and A for ASCII serialization, followed by a new line. (The format used is identical to that used by readRDS.)

So if you are interested in the hash over the normal ASCII data, use:

digest::digest('testing',algo='md5', serialize = FALSE)

Upvotes: 5

Related Questions