I have a server that does create a hash using the following code:
base64_encode(md5("some value", true))
What I have to do is to produce the same hash value in Clojure (using Java interop). What I did is to create the following Clojure functions:
(defn md5-raw [s]
(let [algorithm (java.security.MessageDigest/getInstance "MD5")
size (* 2 (.getDigestLength algorithm))]
(.digest algorithm (.getBytes s))))
(defn bytes-to-base64-string [bytes]
(String. (b64/encode bytes) "UTF-8"))
Then I use that code that way:
(bytes-to-base64-string (md5-raw "some value")
Now, everything works fine with normal strings. However, after processing multiple different examples, I found the the following character is causing issues:
’
This is the UTF-8
character #8217
.
If I run the following PHP
code:
base64_encode(md5("’", true))
What is returned is:
yOy9/y97p/GfapveLVQAHA==
If I run the following Clojure
code:
(bytes-to-base64-string (md5-raw "’"))
I get the following value:
aF1ZConzUtEGRN2YXaKpoQ==
Why is that? I am suspecting a character encoding issue, but everything appears to be handled as UTF-8 as far as I can see.