tags:

views:

306

answers:

2

Hi, 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.

A: 

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.

Jon Skeet
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
+1  A: 

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,...>>

Zed