4
我無法在Erlang中「pem_entry_decode」GPG公鑰。通過OpenSSL生成的公鑰工作正常。我已經按照Erlang - Importing GPG Public Key中的建議修復了GPG密鑰。在Erlang中解碼PGP密鑰
#!/usr/local/bin/escript
main(_) ->
[application:start(X) || X <- [crypto, public_key, ssl]],
Msg = list_to_binary("Hello World!"),
%{ok, FileContents} = file:read_file("public_openssl.pem"),
{ok, FileContents} = file:read_file("public_gpg.asc"),
show(FileContents),
[Entry] = public_key:pem_decode(FileContents),
show(Entry),
Key = public_key:pem_entry_decode(Entry),
show(Key),
EM = public_key:encrypt_public(Msg, Key),
show(EM).
show(Something) ->
io:format("~p~n", [Something]).
錯誤:
escript: exception error: no match of right hand side value
{error,
{asn1,
{wrong_tag,
{{expected,16},{got,131097,{131097,<<"\r">>}}}}}}
in function public_key:der_decode/2 (public_key.erl, line 170)
in call from erl_eval:do_apply/6 (erl_eval.erl, line 572)
in call from erl_eval:expr/5 (erl_eval.erl, line 367)
in call from escript:eval_exprs/5 (escript.erl, line 850)
in call from erl_eval:local_func/5 (erl_eval.erl, line 470)
in call from escript:interpret/4 (escript.erl, line 768)
in call from escript:start/1 (escript.erl, line 277)
in call from init:start_it/1
源代碼是否與錯誤堆棧一致?錯誤堆棧提到public_key:der_decode,而源代碼提到public_key:pem_decode ... – user803422 2013-03-28 11:57:10
我檢查了public_key.erl。 'der_decode'由'pem_entry_decode'調用。不知道爲什麼它不顯示整個堆棧。 – ram 2013-03-28 12:49:50
我建議你嘗試在一個更新的Erlang版本中重現這個問題,比如在R16B中。有消息稱現在對各種DER編碼的東西更加友好,甚至有點畸形。 – Keynslug 2013-06-10 12:48:36