[erlang-questions] public_key:pem_decode/1 and public_key:verify/4

Seth Falcon <>
Mon Jan 31 19:27:54 CET 2011


Hi Ingela,

I've updated my patch:

    https://github.com/seth/otp/tree/sf/rsa_pub_key

it now includes basic tests for decoding and encoding both RSA and DSA
public keys in the SubjectPublicKeyInfo format.  After moving all
lib/FOO/test directories with references to wx, I was able to run the
tests for public_key on my OS X laptop :-)

Here's the summary of where I ended up:

    {ok, RSAPubPem} = file:read_file(filename:join(Datadir, "rsa_pub.pem")),
    [{'SubjectPublicKeyInfo', _, _} = PubEntry1] =
        public_key:pem_decode(RSAPubPem),
    RSAPubKey = public_key:pem_entry_decode(PubEntry1),
    true = check_entry_type(RSAPubKey, 'RSAPublicKey'),
    PubEntry1 = public_key:pem_entry_encode('RSAPublicKey', RSAPubKey),

Notes:

- I haven't merged in the trivial patch from Joakim to allow reading
  RSA public keys in "unwrapped" form where the PEM header has "RSA
  Public Key".

- RSA public key records get encoded into the SubjectPublicKeyInfo
  wrapper form.  So to create the form that Joakim is dealing with,
  one would have to use der_encode directly I believe.

- When encoding RSAPublic keys, there is a parameter spot where it
  seems the right thing to put is <<5, 0>>, but I wanted to mention
  this in case I'm wrong about this being the right value for all RSA
  public keys in SPKI form.

Let me know what else I can do to help get this patch into the
public_key module :-)

Best,

+ seth

-- 
Seth Falcon | @sfalcon | http://userprimary.net/


More information about the erlang-questions mailing list