X509证书格式

时间:2013-03-20 17:17:21

标签: c# x509certificate

当我X509Certificate2 x509 = new X509Certificate2(certificateFile);证书需要采用何种格式?

我有一把私钥:

-----BEGIN RSA PRIVATE KEY-----
......
-----END RSA PRIVATE KEY-----

和证书:

Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
           ..............
        Signature Algorithm: sha1WithRSAEncryption
        Issuer: C=IL, ST=SS, L=...., O=....., OU=....., CN=...../emailAddress=.....
        Validity
            Not Before: Mar 19 14:45:09 2013 GMT
            Not After : Mar 19 14:45:09 2014 GMT
        Subject: C=IL, ST=SS, L=...., O=....., OU=....., CN=...../emailAddress=.....
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Modulus:
                    ...................
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Subject Key Identifier: 
                .........
            X509v3 Authority Key Identifier: 
                keyid:..........

            X509v3 Basic Constraints: 
                CA:TRUE
    Signature Algorithm: sha1WithRSAEncryption
        .....

然而,我无法使用上面的C#代码加载。我错过了什么?

1 个答案:

答案 0 :(得分:1)

-----BEGIN RSA PRIVATE KEY-----是PKCS#1格式(未加密)的RSA私钥的标头。此格式用于私钥PEM文件。

.NET Framework不提供任何现成的方法来直接导出此格式的私钥,因此您必须自己实现它。

This document可以帮助您 - 有一个解码RSA私钥的示例。编码只是反向操作。