<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Oh, I see. I thought the two functions <span style="font-family:monospace">public_key:pem_decode/1 and </span><span style="font-family:monospace">public_key:pem_entry_decode/1 </span>need to be used in succession to decode the entry.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jul 10, 2021 at 6:59 AM Stanislav Ledenev <<a href="mailto:s.ledenev@gmail.com">s.ledenev@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"><div dir="ltr">Your Entry is already decoded, so no need to decode it again.<div>It must be something like {'RSAPublicKey',.....}</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">пт, 9 июл. 2021 г. в 22:09, Serge <<a href="mailto:saleyn@gmail.com" target="_blank">saleyn@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-family:arial,helvetica,sans-serif">Does anyone have an idea how to decode a PGP public key using public_key module?</div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">I am doing this:</div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif"><span style="font-family:monospace"><span style="color:rgb(255,215,215);background-color:rgb(255,255,255)">1> {</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">ok</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">, </span><span style="font-weight:bold;color:rgb(84,255,255);background-color:rgb(255,255,255)">B</span><span style="color:rgb(255,215,215);background-color:rgb(255,255,255)">}</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> </span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)">=</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> file:read_file(PGPPubKey</span><span style="font-weight:bold;color:rgb(84,255,255);background-color:rgb(255,255,255)">File</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">),</span><br></span></div><div style="font-family:arial,helvetica,sans-serif"><span style="color:rgb(255,189,178);font-family:monospace">2></span><span style="color:rgb(255,189,178);font-family:monospace"> </span><span style="font-family:monospace"><span style="font-weight:bold;color:rgb(84,255,255);background-color:rgb(255,255,255)">B1</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> </span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)">=</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> re:replace(</span><span style="font-weight:bold;color:rgb(84,255,255);background-color:rgb(255,255,255)">B</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">, </span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)"><<</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">"-----BEGIN PGP PUBLIC KEY BLOCK-----"</span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)">>></span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">, </span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)"><<</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">"-----BEGIN RSA PUBLIC KEY-----"</span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)">>></span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">, </span><span style="color:rgb(255,215,215);background-color:rgb(255,255,255)">[{</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">return</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">, </span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">binary</span><span style="color:rgb(255,215,215);background-color:rgb(255,255,255)">}]</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">),
</span><br></span><span style="color:rgb(255,189,178);font-family:monospace">3> </span><span style="font-family:monospace"><span style="font-weight:bold;color:rgb(84,255,255);background-color:rgb(255,255,255)">B2</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> </span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)">=</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> re:replace(</span><span style="font-weight:bold;color:rgb(84,255,255);background-color:rgb(255,255,255)">B1</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">,  </span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)"><<</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">"-----END PGP PUBLIC KEY BLOCK-----"</span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)">>></span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">, </span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)"><<</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">"-----END RSA PUBLIC KEY-----"</span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)">>></span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">,   </span><span style="color:rgb(255,215,215);background-color:rgb(255,255,255)">[{</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">return</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">, </span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">binary</span><span style="color:rgb(255,215,215);background-color:rgb(255,255,255)">}]</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">),
</span><br></span><span style="color:rgb(255,189,178);font-family:monospace">4> </span><span style="font-family:monospace"><span style="font-weight:bold;color:rgb(84,255,255);background-color:rgb(255,255,255)">B3</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> </span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)">=</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> re:replace(</span><span style="font-weight:bold;color:rgb(84,255,255);background-color:rgb(255,255,255)">B2</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">,  </span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)"><<</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">"</span><span style="color:rgb(255,215,215);background-color:rgb(255,255,255)">\n</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">.+(</span><span style="color:rgb(255,215,215);background-color:rgb(255,255,255)">\n</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">-----END)"</span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)">>></span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">,    </span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)"><<</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">"</span><span style="color:rgb(255,215,215);background-color:rgb(255,255,255)">\\</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">1"</span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)">>></span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">, </span><span style="color:rgb(255,215,215);background-color:rgb(255,255,255)">[{</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">return</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">, </span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">binary</span><span style="color:rgb(255,215,215);background-color:rgb(255,255,255)">}]</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">), </span><span style="color:rgb(84,255,255);background-color:rgb(255,255,255)">% Remove checksum</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br></span><span style="color:rgb(255,189,178);font-family:monospace">5> </span><span style="font-family:monospace"><span style="font-weight:bold;color:rgb(84,255,255);background-color:rgb(255,255,255)">B4</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> </span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)">=</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> re:replace(</span><span style="font-weight:bold;color:rgb(84,255,255);background-color:rgb(255,255,255)">B3</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">,  </span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)"><<</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">"</span><span style="color:rgb(255,215,215);background-color:rgb(255,255,255)">\n</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">Version:.+</span><span style="color:rgb(255,215,215);background-color:rgb(255,255,255)">\n\r</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">?</span><span style="color:rgb(255,215,215);background-color:rgb(255,255,255)">\n</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">"</span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)">>></span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">, </span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)"><<</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">"</span><span style="color:rgb(255,215,215);background-color:rgb(255,255,255)">\n</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">"</span><span style="color:rgb(255,255,84);background-color:rgb(255,255,255)">>></span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">,  </span><span style="color:rgb(255,215,215);background-color:rgb(255,255,255)">[{</span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">return</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">, </span><span style="color:rgb(255,84,255);background-color:rgb(255,255,255)">binary</span><span style="color:rgb(255,215,215);background-color:rgb(255,255,255)">}]</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">), </span><span style="color:rgb(84,255,255);background-color:rgb(255,255,255)">% Remove version</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br></span><span style="color:rgb(255,189,178);font-family:monospace">6> </span><span style="font-family:monospace">[Entry] = public_key:pem_decode(<span style="font-weight:bold;color:rgb(84,255,255);background-color:rgb(255,255,255)">B4</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">),</span><br></span></div><div style="font-family:arial,helvetica,sans-serif"><span style="color:rgb(255,189,178);font-family:monospace">7></span><span style="color:rgb(255,189,178);font-family:monospace"> </span><span style="font-family:monospace"><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">public_key:pem_entry_decode(Entry).                                                </span><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></span></div></div>
</blockquote></div>
</blockquote></div></div>