Re: PGP public key decoding

Stanislav Ledenev <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <CAOkK=AJqWCH7tqAQ4nDi3xeFmBVVZMVWUxyhhVqHHwxL8z+LRg@mail.gmail.com>
Your Entry is already decoded, so no need to decode it again.
It must be something like {'RSAPublicKey',.....}

пт, 9 июл. 2021 г. в 22:09, Serge <[email protected]>:

> Does anyone have an idea how to decode a PGP public key using public_key
> module?
>
> I am doing this:
>
> 1> {ok, B} = file:read_file(PGPPubKeyFile),
> 2> B1 = re:replace(B, <<"-----BEGIN PGP PUBLIC KEY BLOCK-----">>, <<"-----BEGIN
> RSA PUBLIC KEY-----">>, [{return, binary}]),
> 3> B2 = re:replace(B1,  <<"-----END PGP PUBLIC KEY BLOCK-----">>,   <<"-----END
> RSA PUBLIC KEY-----">>,   [{return, binary}]),
> 4> B3 = re:replace(B2,  <<"\n.+(\n-----END)">>,    <<"\\1">>, [{return,
> binary}]), % Remove checksum
> 5> B4 = re:replace(B3,  <<"\nVersion:.+\n\r?\n">>, <<"\n">>,  [{return,
> binary}]), % Remove version
> 6> [Entry] = public_key:pem_decode(B4),
> 7> public_key:pem_entry_decode(Entry).
>
> ** exception error: no match of right hand side value
> {error,{asn1,{{wrong_tag,{{expected,16},
>                                                                                {got,131097,{131097,<<"\r">>}}}},
>
>                                                                    [{'OTP-PUB-KEY',match_tags,2,
>
>                                                                                    [{file,"OTP-PUB-KEY.erl"},{line,23999}]},
>
>                                                                     {'OTP-PUB-KEY',dec_RSAPublicKey,2,
>
>                                                                                    [{file,"OTP-PUB-KEY.erl"},{line,2957}]},
>
>                                                                     {'OTP-PUB-KEY',decode,2,
>
>                                                                                    [{file,"OTP-PUB-KEY.erl"},{line,1232}]},
>
>                                                                     {public_key,der_decode,2,
>
>                                                                                 [{file,"public_key.erl"},{line,318}]},
>
>                                                                     {erl_eval,do_apply,6,[{file,"erl_eval.erl"},{line,689}]},
>
>                                                                     {shell,exprs,7,[{file,"shell.erl"},{line,686}]},
>
>                                                                     {shell,eval_exprs,7,[{file,"shell.erl"},{line,642}]},
>
>                                                                     {shell,eval_loop,3,[{file,"shell.erl"},{line,627}]}]}}}
>
>     in function  public_key:der_decode/2 (public_key.erl, line 322)
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.