sha256 encryption in erlang

折月煮酒 提交于 2019-12-06 09:23:39

问题


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.


回答1:


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.




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



来源:https://stackoverflow.com/questions/955161/sha256-encryption-in-erlang

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!