如何使用充气城堡在CSR中添加自定义OID和值

时间:2017-12-27 05:48:37

标签: c# bouncycastle csr pkcs11interop pkcs#10

我正在尝试在CSR中添加自定义OID

string subject = "CN=Name,O=Org,C=IN,ST=KA,OU=OrgUn,PostalCode=560103";
X509Name sub = new X509Name(subject);
var oidList = sub.GetOidList();
var valueList = sub.GetValueList();

DerObjectIdentifier Oid1 = new derObjectIdentifier("1.53.4.64");//here 1.53.4.64 is custom OID
oidList.Add(Oid1);
valueList.Add("Some Value");

DerObjectIdentifier Oid2 = new DerObjectIdentifier("1.53.4.65");
oidList.Add(derObjectIdentifier2);
valueList.Add("Some value");

X509Name subjectFinal = new X509Name(oidList, valueList);

Pkcs10CertificationRequestDelaySigned pkcs10 = new Pkcs10CertificationRequestDelaySigned(signatureAlgorihtm, subjectFinal, publicKeyParameters, null);

所有内容编译并正常工作但是当我解码并检查CSR时,自定义Oid名称的值在ASN.1信息中从1.53.4.65更改为其他值2.13.4.64

这是添加自定义OID值的正确方法

ASN.1序列

SET {
 16  11:         SEQUENCE {
 18   3:           OBJECT IDENTIFIER commonName (2 5 4 3)
 23   4:           UTF8String 'Name'
       :           }
       :         }
 29  12:       SET {
 31  10:         SEQUENCE {
 33   3:           OBJECT IDENTIFIER organizationName (2 5 4 10)
 38   3:           UTF8String 'Org'
       :           }
       :         }
 43  11:       SET {
 45   9:         SEQUENCE {
 47   3:           OBJECT IDENTIFIER countryName (2 5 4 6)
 52   2:           PrintableString 'IN'
       :           }
       :         }
 56  11:       SET {
 58   9:         SEQUENCE {
 60   3:           OBJECT IDENTIFIER stateOrProvinceName (2 5 4 8)
 65   2:           UTF8String 'KA'
       :           }
       :         }
 69  14:       SET {
 71  12:         SEQUENCE {
 73   3:           OBJECT IDENTIFIER organizationalUnitName (2 5 4 11)
 78   5:           UTF8String 'OrgUn'
       :           }
       :         }
 85  15:       SET {
 87  13:         SEQUENCE {
 89   3:           OBJECT IDENTIFIER postalCode (2 5 4 17)
 94   6:           UTF8String '560103'
       :           }
       :         }
102  21:       SET {
104  19:         SEQUENCE {
106   3:           OBJECT IDENTIFIER '2 13 4 64'
111  12:           UTF8String 'Some value 1'
       :           }
       :         }
125  21:       SET {
127  19:         SEQUENCE {
129   3:           OBJECT IDENTIFIER '2 13 4 65'
134  12:           UTF8String 'Some value 2'
       :           }
       :         }

1 个答案:

答案 0 :(得分:2)

添加自定义OID属性的代码是正确的,但是我们不能使用任何随机数作为OID,它必须为ex 1.3.6.1.4.1.XXXX.X.X注册,或者它必须具有某种格式。