2

i have written some code in php there i have use mhash(MHASH_SHA256, $key) and its giving result as expected.i wanna know how we can achieve same thing in erlang.i can see in crypto their is one inbuild sha function is their but i dont think so its mean for sha256.

any suggestion what i have to do ?

thank you in advance.

2 Answers 2

4

Have you seen this page, which links to an SHA-256 module for Erlang?

EDIT: Apparently that code is obsolete, replaced by this module. If that still doesn't do what you want (in terms of hex/binary) I suggest you email its author, preferably with a patch.

1
  • The problem is the sha-256 module generates sha in hex mode whereas I want it in binary. Of course it can be converted, but thought there would be someway to avoid the conversion
    – Abhimanyu
    Jun 5, 2009 at 10:28
2

It seems to me that the return value of the mentioned sha2 module depends on your input. If you call it with a binary, the result is binary; if you call it with a string, the result is a string:

sha2:hexdigest256("Zed"). "a90e4dc685583c72296ca49b5d0bb148f2e1197a805b2a1d2ff6d17b4398b2be"

sha2:hexdigest256(<<"Zed">>). <<169,14,77,198,133,88,60,114,41,108,164,155,93,11,177,72, 242,225,25,122,128,91,42,29,47,246,209,123,67,...>>

Your Answer

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

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