<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">I followed the key re-formatting advice mentioned here:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><a href="https://stackoverflow.com/questions/10966256/erlang-importing-gpg-public-key">https://stackoverflow.com/questions/10966256/erlang-importing-gpg-public-key</a></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">However, as shown, <span style="font-family:Arial,Helvetica,sans-serif">public_key:pem_entry_decode/1 fails.</span></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 9, 2021 at 7:43 PM Max Lapshin <<a href="mailto:max.lapshin@gmail.com">max.lapshin@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><a href="https://datatracker.ietf.org/doc/html/rfc4880" rel="noreferrer" target="_blank">https://datatracker.ietf.org/doc/html/rfc4880</a><br>
<br>
1. maybe it is not base64, but radix64 and it could be another thing?<br>
2. is it really ASN?<br>
<br>
On Fri, Jul 9, 2021 at 10:09 PM Serge <<a href="mailto:saleyn@gmail.com" target="_blank">saleyn@gmail.com</a>> wrote:<br>
><br>
> Does anyone have an idea how to decode a PGP public key using public_key module?<br>
><br>
> I am doing this:<br>
><br>
> 1> {ok, B} = file:read_file(PGPPubKeyFile),<br>
> 2> B1 = re:replace(B, <<"-----BEGIN PGP PUBLIC KEY BLOCK-----">>, <<"-----BEGIN RSA PUBLIC KEY-----">>, [{return, binary}]),<br>
> 3> B2 = re:replace(B1,  <<"-----END PGP PUBLIC KEY BLOCK-----">>,   <<"-----END RSA PUBLIC KEY-----">>,   [{return, binary}]),<br>
> 4> B3 = re:replace(B2,  <<"\n.+(\n-----END)">>,    <<"\\1">>, [{return, binary}]), % Remove checksum<br>
> 5> B4 = re:replace(B3,  <<"\nVersion:.+\n\r?\n">>, <<"\n">>,  [{return, binary}]), % Remove version<br>
> 6> [Entry] = public_key:pem_decode(B4),<br>
> 7> public_key:pem_entry_decode(Entry).<br>
> ** exception error: no match of right hand side value {error,{asn1,{{wrong_tag,{{expected,16},<br>
>                                                                                {got,131097,{131097,<<"\r">>}}}},<br>
>                                                                    [{'OTP-PUB-KEY',match_tags,2,<br>
>                                                                                    [{file,"OTP-PUB-KEY.erl"},{line,23999}]},<br>
>                                                                     {'OTP-PUB-KEY',dec_RSAPublicKey,2,<br>
>                                                                                    [{file,"OTP-PUB-KEY.erl"},{line,2957}]},<br>
>                                                                     {'OTP-PUB-KEY',decode,2,<br>
>                                                                                    [{file,"OTP-PUB-KEY.erl"},{line,1232}]},<br>
>                                                                     {public_key,der_decode,2,<br>
>                                                                                 [{file,"public_key.erl"},{line,318}]},<br>
>                                                                     {erl_eval,do_apply,6,[{file,"erl_eval.erl"},{line,689}]},<br>
>                                                                     {shell,exprs,7,[{file,"shell.erl"},{line,686}]},<br>
>                                                                     {shell,eval_exprs,7,[{file,"shell.erl"},{line,642}]},<br>
>                                                                     {shell,eval_loop,3,[{file,"shell.erl"},{line,627}]}]}}}<br>
>     in function  public_key:der_decode/2 (public_key.erl, line 322)<br>
</blockquote></div>