【问题标题】:Decoding PGP keys in Erlang在 Erlang 中解码 PGP 密钥
【发布时间】:2013-03-27 12:05:53
【问题描述】:

我无法在 Erlang 中“pem_entry_decode”GPG 公钥。通过 OpenSSL 生成的公钥可以正常工作。我已经按照Erlang - Importing GPG Public Key 中的建议修复了 GPG 密钥。

#!/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...
  • 我签入了 public_key.erl。 der_decodepem_entry_decode 调用。不知道为什么它没有显示整个堆栈。
  • 我建议您尝试在较新的 Erlang 版本中重现此问题,例如在 R16B 中。有消息说它现在对各种 DER 编码的东西更加友好,甚至有点畸形。

标签: erlang gnupg openpgp


【解决方案1】:

来自您的:

{ok, FileContents} = file:read_file("public_gpg.asc")

FileContents,选择前 16 个字符。

【讨论】:

    猜你喜欢
    • 2020-12-13
    • 1970-01-01
    • 2019-03-26
    • 2021-09-04
    • 2012-05-06
    • 1970-01-01
    • 2020-01-08
    • 1970-01-01
    • 2018-05-22
    相关资源
    最近更新 更多