I am having trouble converting this:


Into this:


It is for a web based program (I need to get a signature for authentication) and using online converters to check if what I am doing is right, I have managed to successfully convert "333" both into SHA512 and Base64 in Mathematica.

(* String to SHA512 *)
In[1]=  IntegerString[
          Hash["333", "SHA512"],
Out[1]= 5e3155774d39d97c5f9e17c108c2b3e0485a43ae34ebd196f61a6f8bf732ef71a49e5710594cfc7391db114edf99f5da3ed96ef1d6ca5e598e85f91bd41e7eeb
(* verified correct using http://www.unit-conversion.info/texttools/sha/#data *)

(* String to Base64 *)
In[2]=  ExportString[
Out[2]= MzMz
(* verified correct using http://www.unit-conversion.info/texttools/base64/#data *)

But when I combine the two, I get this:

(* String to SHA512 Base64 *)
In[3]=  ExportString[
          IntegerString[Hash["333", "SHA512"], 16],

Instead of:



Any ideas on how this could be done?

PS: I found a function for Mathematica 11.2 called "SecuredAuthenticationKey" that could be related to what I am trying to do. I am currently using Mathematica 9.


2 Answers 2

      Hash["333", "SHA512"],
(* XjFVd0052XxfnhfBCMKz4EhaQ64069GW9hpvi/cy73GknlcQWUz8c5HbEU7fmfXaPtlu8dbKXlmOhfkb1B5+6w== *)

Your use of IntegerString converts it to base-16 first, but it looks like you want to convert it on a per-bit level, so divide it into bytes (with IntegerDigits), convert to string (FromCharacterCode), and apply ExportString there.

  • $\begingroup$ Thank you sir! :D $\endgroup$
    – user12572
    Dec 27, 2017 at 21:43

This is much easier to do as of the recently released version 11.3.0:

BaseEncode[Hash["333", "SHA512", "ByteArray"]]

(* "XjFVd0052XxfnhfBCMKz4EhaQ64069GW9hpvi/cy73GknlcQWUz8c5HbEU7fmfXaPtlu8dbKXlmOhfkb1B5+6w==" *)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.