为什么.cer文件公钥不包含RSA Exponent?

时间:2014-05-09 17:39:04

标签: cryptography rsa x509certificate

我使用以下代码生成公钥和私钥:

using (var rsaProvider = new RSACryptoServiceProvider(cspParams))
{
    try
    {
        // Export public key
        publicKey = rsaProvider.ToXmlString(false);
        // Write public key to file
        publicKeyFile = File.CreateText(publicKeyFileName);
        publicKeyFile.Write(publicKey);

        // Export private/public key pair 
        //privateKey = rsaProvider.ToXmlString(true);
        privateKey = rsaProvider.ToXmlString(true);

        // Write private/public key pair to file
        privateKeyFile = File.CreateText(privateKeyFileName);
        privateKeyFile.Write(privateKey);
    }
    catch (Exception ex)
    {
    }
    finally
    {
        rsaProvider.PersistKeyInCsp = false; // dont srotre in windows key container
    }
}

生成的公钥包含密钥和expontent:

<RSAKeyValue
    <Modulus>rx39KaNggx7IFO/CT2XTi/aHdgEnZq0f6E2lKFVbObZ9ws0wCsRftfomOOy2z8/jFXn7NLOuiC+MvO6AsSb8nSCO0PY08TklmFBzsFxsq7CLWubL8TDV0wq7AtVpovdJkywc+O4wnz8ZTn38nAgNnQ6Ga+hIJspFCYZS01jkx30=    
    </Modulus>
    <Exponent>AQAB</Exponent>
</RSAKeyValue>

但是当我从Internet Explorer查看证书的公钥时,它会显示:

RSA(2048位)。

30 82 01 0a 02 82 01 01 00 bf 61 0a 29 10 1f 5e
fe 34 37 51 08 f8 1e fb 22 ed 61 be 0b 0d 70 4c
50 63 26 75 15 b9 41 88 97 b6 f0 a0 15 bb 08 60
e0 42 e8 05 29 10 87 36 8a 28 65 a8 ef 31 07 74
6d 36 97 2f 28 46 66 04 c7 2a 79 26 7a 99 d5 8e
c3 6d 4f a0 5e ad bc 3d 91 c2 59 7b 5e 36 6c c0
53 cf 00 08 32 3e 10 64 58 10 13 69 c7 0c ee 9c
42 51 00 f9 05 44 ee 24 ce 7a 1f ed 8c 11 bd 12
a8 f3 15 f4 1c 7a 31 69 01 1b a7 e6 5d c0 9a 6c
7e 09 9e e7 52 44 4a 10 3a 23 e4 9b b6 03 af a8
9c b4 5b 9f d4 4b ad 92 8c ce b5 11 2a aa 37 18
8d b4 c2 b8 d8 5c 06 8c f8 ff 23 bd 35 5e d4 7c
3e 7e 83 0e 91 96 05 98 c3 b2 1f e3 c8 65 eb a9
7b 5d a0 2c cc fc 3c d9 6d ed cc fa 4b 43 8c c9
d4 b8 a5 61 1c b2 40 b6 28 12 df b9 f8 5f fe d3
b2 c9 ef 3d b4 1e 4b 7c 1c 4c 99 36 9e 3d eb ec
a7 68 5e 1d df 67 6e 5e fb 02 03 01 00 01

这是包含指数的相同类型的密钥,还是编码的密钥,或者只是不同类型的加密?

1 个答案:

答案 0 :(得分:3)

它只是对相同信息的不同编码。一个是XML,使用base-64编码来表示模数和指数。另一种是使用与PKI协议共同的可分辨编码规则(DER)的信息的十六进制编码。它是一个&#34; SEQUENCE&#34;包含两个&#34; INTEGER&#34;元素:模数和指数,如the PKCS #1 standard.

中所定义
30 - SEQUENCE tag
    82 01 0a - length is 266 bytes
  02 - INTEGER tag (modulus)
      82 01 01 - length is 257 bytes
    00 bf 61 0a 29 10 1f 5e
    fe 34 37 51 08 f8 1e fb 22 ed 61 be 0b 0d 70 4c
    50 63 26 75 15 b9 41 88 97 b6 f0 a0 15 bb 08 60
    e0 42 e8 05 29 10 87 36 8a 28 65 a8 ef 31 07 74
    6d 36 97 2f 28 46 66 04 c7 2a 79 26 7a 99 d5 8e
    c3 6d 4f a0 5e ad bc 3d 91 c2 59 7b 5e 36 6c c0
    53 cf 00 08 32 3e 10 64 58 10 13 69 c7 0c ee 9c
    42 51 00 f9 05 44 ee 24 ce 7a 1f ed 8c 11 bd 12
    a8 f3 15 f4 1c 7a 31 69 01 1b a7 e6 5d c0 9a 6c
    7e 09 9e e7 52 44 4a 10 3a 23 e4 9b b6 03 af a8
    9c b4 5b 9f d4 4b ad 92 8c ce b5 11 2a aa 37 18
    8d b4 c2 b8 d8 5c 06 8c f8 ff 23 bd 35 5e d4 7c
    3e 7e 83 0e 91 96 05 98 c3 b2 1f e3 c8 65 eb a9
    7b 5d a0 2c cc fc 3c d9 6d ed cc fa 4b 43 8c c9
    d4 b8 a5 61 1c b2 40 b6 28 12 df b9 f8 5f fe d3
    b2 c9 ef 3d b4 1e 4b 7c 1c 4c 99 36 9e 3d eb ec
    a7 68 5e 1d df 67 6e 5e fb
  02 - INTEGER tag (public exponent)
      03 - length is 3 bytes
    01 00 01 (65,537 [F4])