Abhimanyu
Abhimanyu

Reputation: 369

sha256 encryption in erlang

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.

Upvotes: 2

Views: 3293

Answers (2)

Zed
Zed

Reputation: 57658

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

Upvotes: 2

Jon Skeet
Jon Skeet

Reputation: 1501033

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.

Upvotes: 4

Related Questions