0

对此的跟进。

我得到了阅读/解码工作

1> {ok, F} = file:read_file("inaimathi.rsapub").
{ok,<<"-----BEGIN RSA PUBLIC KEY-----\nmQINBE9NBIQBEADMSzN6b0FaPP0rGiLDWKfH4ehN66Z0SAIynXm6lBHjmO69pNsm\niIe4p1X9aXhr"...>>}
2> [Entry] = public_key:pem_decode(F).
[{'RSAPublicKey',<<153,2,13,4,79,77,4,132,1,16,0,204,75,
                   51,122,111,65,90,60,253,43,26,34,195,
                   88,167,...>>,
                 not_encrypted}]

根据文档,为了从中获得一个有效的公钥,我要做的最后一件事就是在public_key:pem_entry_decode/1上面运行Entry。但是,当我尝试这样做时,我得到了一个错误。

3> public_key:pem_entry_decode(Entry).
** exception error: no match of right hand side value 
                    {error,
                        {asn1,
                            {{badmatch,{error,{asn1,{wrong_tag,{131097,16}}}}},
                             [{'OTP-PUB-KEY',dec_RSAPublicKey,2,
                                  [{file,"OTP-PUB-KEY.erl"},{line,5956}]},
                              {'OTP-PUB-KEY',decode,2,
                                  [{file,"OTP-PUB-KEY.erl"},{line,493}]},
                              {public_key,der_decode,2,
                                  [{file,"public_key.erl"},{line,166}]},
                              {erl_eval,do_apply,6,
                                  [{file,"erl_eval.erl"},{line,576}]},
                              {shell,exprs,7,[{file,"shell.erl"},{line,668}]},
                              {shell,eval_exprs,7,
                                  [{file,"shell.erl"},{line,623}]},
                              {shell,eval_loop,3,
                                  [{file,"shell.erl"},{line,608}]}]}}}
     in function  public_key:der_decode/2 (public_key.erl, line 170)

我在这里做错了什么?

编辑:不认为这很重要,但有人问,所以。

我在 Core i3 上运行 Debian Wheezy,安装了 Erlang,这是从大约 2 天前的结帐开始

erl --version

Erlang R15B02 (erts-5.9.2) [source] [64-bit] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false]
4

1 回答 1

5

您的代码在这里工作正常:

decode() ->
    [application:start(X) || X <- [crypto, public_key, ssl]],
    RawData = ["-----BEGIN PUBLIC KEY-----\n",
               "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDBm8yuHmd0P6scl48DEi+xp47w\n",
               "XVZaKWRygGKtA2XkdRuCU99f0Tq07Llcgf8XuR+Wnk+z2CdMMFMzOGhCePblVIAn\n",
               "33dcBVlDokpBF7AnTClsaLcixxZw1LIUiaPaBdN7oG8vt3G2caLHRrrkoEnccY+6\n",
               "GadfH7iuHdcVsz1mowIDAQAB\n",
               "-----END PUBLIC KEY-----"],
    D = iolist_to_binary(RawData),
    [Entry] = public_key:pem_decode(D),
    public_key:pem_entry_decode(Entry).

生成输出(缩短):

 {'RSAPublicKey',135956...,65537}
于 2012-06-10T20:42:23.473 回答