How do I determine the "modulus" and "exponent" for RSAParameters

1.1k views Asked by At

I have an RSA (x509 certificate) that I want to use in a C# program.

I've done some research and apparently I need to import two things using RSAParameters: The modulus, and the exponent.

All I know how to use is a key block like the one above, how do I take a key block and get the modulus and exponent? I tried MSDN but the documentation doesn't say much.

Also, those two fields are supposed to be in byte[] format, can I convert them directly (I have a method Utility.ToByteArray()) or do they need to be encoded in a certain way first.

Thanks!

1

There are 1 answers

3
Razick On

Use openssl to get the modulus and exponent from an existing certificate file: openssl x509 -in public.crt -text

This outputs something like the following:

Certificate:
Data:
    Version: 3 (0x2)
    Serial Number: 16219001685648037895 (0xe2237819e4835807)
Signature Algorithm: sha1WithRSAEncryption
    Issuer: C=US, ST=State, L=City, O=Company, OU=Cirrus/[email protected]
    Validity
        Not Before: Dec  9 14:18:31 2013 GMT
        Not After : Dec  9 14:18:31 2014 GMT
    Subject: C=US, ST=State, L=City, O=Company, OU=Unit/[email protected]
    Subject Public Key Info:
        Public Key Algorithm: rsaEncryption
            Public-Key: (1024 bit)
            Modulus:
                11:aa:41:47:f2:80:b9:6f:26:8c:19:c8:a4:0d:4a:
                51:d3:a6:87:5b:88:2a:69:7a:c0:2c:5d:cc:fe:6b:
                ed:d9:fa:bb:a0:2c:5a:76:90:b5:47:4f:01:7b:0f:
                03:51:2e:2b:44:e0:1e:a4:d7:a7:0d:a4:ae:9b:25:
                0f:10:42:ab:d5:42:a8:8e:ed:e4:34:eb:73:5a:79:
                a9:a5:40:0d:9b:ee:65:33:02:5e:cc:ec:ce:7f:0e:
                c7:14:21:43:43:82:17:db:fa:77:81:0a:4d:d8:98:
                41:48:88:06:4f:12:ec:3b:66:5d:f4:0c:44:c5:14:
                73:23:cf:9d:ec:42:3b:38:d9
            Exponent: 65537 (0x10001)
    X509v3 extensions:
        X509v3 Subject Key Identifier: 
            C5:30:71:FB:92:F1:FC:9B:57:DA:65:A6:97:10:28:C4:A6:59:28:72
        X509v3 Authority Key Identifier: 
            keyid:C5:33:71:FB:99:F1:FC:9B:58:D8:65:A6:97:10:28:C4:A6:59:28:82