c# - What is needed to convert ASN.1 data to a Public Key? e.g. how do I determine the OID? -


this code relates dkim signature verification used in anti-spam efforts.

i have byte[] s1024._domainkey.yahoo.com asn.1 encoded, don't know if alone contains enough information materialize public key.

based on this class, appears can convert asn.1 key x509certificate public key, need supply oid , asn.1-encoded parameters.

in example have metadata asn1 key is:

  1. an rsa encoded key (asn.1 der-encoded [itu-x660-1997] rsapublickey per rfc3447)
  2. used either sha1 sha256 hash algorithms
  3. uses oid relating following table section a.2 of rfc3447 (though don't know how turn information full oid)
/*  * 1.2.840.113549.1  *      md2 md2withrsaencryption    ::= {pkcs-1 2}     md5 md5withrsaencryption    ::= {pkcs-1 4}     sha-1 sha1withrsaencryption   ::= {pkcs-1 5}     sha-256 sha256withrsaencryption ::= {pkcs-1 11}     sha-384 sha384withrsaencryption ::= {pkcs-1 12}     sha-512 sha512withrsaencryption ::= {pkcs-1 13}  */ 

code sample

string pubkey = "migfma0gcsqgsib3dqebaquaa4gnadcbiqkbgqdreee0ri4juz+qfiwyui/e9ugsxau/2p8ljntd8v4unn+2fazvge3kl23bzeoulyv4peleb3gfmjidjoku3ns5l4kjauuhjfwdebt0np+sbk0vketatl2yr/s3bt/xhy+1xtj4rkdv7fvxtn56lb4udunwuxk4v5b5pdokj/+xcwidaqab"; byte[] pubkeybytearray = convert.frombase64string(pubkey); asnencodeddata adata = new asnencodeddata(pubkeybytearray);  // oid must not null, here.  it? system.security.cryptography.x509certificates.publickey pubkeyrdr = new system.security.cryptography.x509certificates.publickey(adata.oid, null, adata); 

question

  • what oid should use?
  • what examples of asn.1 parameters?

update

this data have provided when parsed using link @erickson provided:

sequence (2 elem)     sequence (2 elem)         object identifier 1.2.840.113549.1.1.1         null     bit string (1 elem)         sequence (2 elem)             integer(1024 bit)             integer 65537 

the reason previous code throws asn1 bad tag value met. exception because adata contains incorrect data (contains data above). i've seen, how 3 arguments system.security.cryptography.x509certificates.publickey broken down.

  1. the first parameter oid, object identifier above.
  2. the second parameter public key parameters. in parsing above, can see null.
  3. the third parameter actual public key value. made of third sequence above. sequence has 2 integers, 1024-bit modulus followed public exponent.

i tested using code below. couldn't find built-in method parse data without writing der parser.

oid oid = new oid("1.2.840.113549.1.1.1"); asnencodeddata keyvalue = new asnencodeddata(getbytes("30818902818100eb11e7b4462e09bb3f907e2598ba2fc4f541925dabbfd8ff0b8e74c3f15e149e7fb6140655184de42f6ddbcdea142d8bf83de95e07781f98988324e294dcdb392f82890145078c5c0379bb7434ffac04ad1529e4c04cbd98aff4b76d3ff1872fb5c6d8f8464755edf5714e7e7a2dbe2e7549f0bb12b85796f93dd38a8fff97730203010001")); asnencodeddata keyparam = new asnencodeddata(new byte[] {05, 00}); publickey pubkeyrdr = new system.security.cryptography.x509certificates.publickey(oid, keyparam, keyvalue); system.diagnostics.debug.writeline(pubkeyrdr.key.keyexchangealgorithm); system.diagnostics.debug.writeline(pubkeyrdr.key.keysize); 

it outputs rsa-pkcs1-keyex , 1024.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -