<div dir="ltr"><div class="gmail_default" 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 class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">I am doing this:</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"><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 class="gmail_default" 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 class="gmail_default" 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>