title: Erlang - Decoding RSA public Key
body: <p>Follow-up to <a href="https://stackoverflow.com/questions/10966256/erlang-importing-gpg-public-key">this one</a>.</p>
  
  <p>I got the reading/decoding working</p>
  
  <pre><code>1&gt; {ok, F} = file:read_file("inaimathi.rsapub").
  {ok,&lt;&lt;"-----BEGIN RSA PUBLIC KEY-----\nmQINBE9NBIQBEADMSzN6b0FaPP0rGiLDWKfH4ehN66Z0SAIynXm6lBHjmO69pNsm\niIe4p1X9aXhr"...&gt;&gt;}
  2&gt; [Entry] = public_key:pem_decode(F).
  [{'RSAPublicKey',&lt;&lt;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,...&gt;&gt;,
                   not_encrypted}]
  </code></pre>
  
  <p>According to <a href="http://www.erlang.org/doc/apps/public_key/using_public_key.html#id60385" rel="nofollow noreferrer">the docs</a>, the last thing I have to do in order to get a working public key out of this is run <code>public_key:pem_entry_decode/1</code> on that <code>Entry</code>. However, when I try to do that, I get an eror.</p>
  
  <pre><code>3&gt; 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)
  </code></pre>
  
  <p>What am I doing wrong here?</p>
  
  <p><strong>EDIT:</strong> Didn't think it would matter, but someone asked, so. </p>
  
  <p>I'm running Debian Wheezy on a Core i3 with Erlang installed from a ~2 day old checkout of <a href="https://github.com/erlang/otp" rel="nofollow noreferrer">this</a>.</p>
  
  <p><code>erl --version</code> says</p>
  
  <pre><code>Erlang R15B02 (erts-5.9.2) [source] [64-bit] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false]
  </code></pre>