This question already has answers here:
Generating a SHA-256 hash from the Linux command line (8 answers)
Closed last year.
Erlang returns me a different result than the bash command when I "sha256".
echo a | sha256sum, returns: 87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7 -
Erlang
Bin = crypto:hash(sha256, "a").
<<202,151,129,18,202,27,189,202,250,194,49,179,154,35,220,
77,167,134,239,248,20,124,78,114,185,128,119,133,175,
238,72,187>>
I tried different bin to hex from bin to hex None of them gave the result I was expecting.
I got this as a result:
bin_to_hex:bin_to_hex(Bin).
<<"CA978112CA1BBDCAFAC231B39A23DC4DA786EFF8147C4E72B9807785AFEE48BB">>
1条答案
按热度按时间ecr0jaav1#
你的
echo a
将包含一个换行符,当我在erlang版本中添加一个换行符时,我会得到预期的哈希值:您也可以告诉
echo
不要在-n
中使用换行符: