【发布时间】:2013-08-06 11:24:52
【问题描述】:
我尝试使用 crypto:sign/4 对消息进行签名,但失败了。谁能告诉我如何在 Erlang 中使用 ECDSA 签署消息?谢谢。 (我使用的是 Erlang 版本 R16B01。)
模块代码:
-module(message).
-compile(export_all).
go() ->
{_PubKey, PriKey} = crypto:generate_key(ecdh, secp256k1),
SigBin = sign_message(PriKey, "Hello"),
SigBin.
sign_message(PriKey, Msg) ->
Algorithm = ecdsa,
DigestType = sha256,
MsgBin = list_to_binary(Msg),
SigBin = crypto:sign(Algorithm, DigestType, MsgBin, PriKey),
SigBin.
但它在测试运行时失败了:
1> message:go().
** exception error: no function clause matching crypto:sign(ecdsa,sha256,
{digest,
<<24,95,141,179,34,113,254,37,245,97,166,252,147,
139,46,38,67,6,236,48,78,218,81,128,...>>},
<<189,38,200,204,95,248,54,69,42,65,216,165,242,228,100,
54,158,5,61,174,58,198,191,161,9,...>>) (crypto.erl, line 462)
感谢 Paul,通过以下更改可以修复此错误。
改变:
SigBin = crypto:sign(Algorithm, DigestType, MsgBin, PriKey),
到:
SigBin = crypto:sign(Algorithm, DigestType, MsgBin, [PriKey, secp256k1]),
【问题讨论】:
标签: encryption erlang sign ecdsa