예제 #1
0
        public static CertificationRequest Encode(CertificateRequestData requestData)
        {
            var publicKeyBytes = Asn1.Encode(new Sequence(
                                                 new DerInteger(requestData.Key.Modulus),
                                                 new DerInteger(requestData.Key.Exponent)
                                                 ));

            var certificationRequestInfo = new CertificationRequestInfo(
                new DerInteger(0),
                new Name(

                    /*new RelativeDistinguishedName(
                     *  new AttributeTypeAndValue(new ObjectIdentifier(Oid.Attribute.C),
                     *      new PrintableString(requestData.C))),
                     * new RelativeDistinguishedName(
                     *  new AttributeTypeAndValue(new ObjectIdentifier(Oid.Attribute.S), new UTF8String(requestData.S))),
                     * new RelativeDistinguishedName(
                     *  new AttributeTypeAndValue(new ObjectIdentifier(Oid.Attribute.L), new UTF8String(requestData.L))),
                     * new RelativeDistinguishedName(
                     *  new AttributeTypeAndValue(new ObjectIdentifier(Oid.Attribute.O), new UTF8String(requestData.O))),
                     * new RelativeDistinguishedName(
                     *  new AttributeTypeAndValue(new ObjectIdentifier(Oid.Attribute.OU), new UTF8String(requestData.OU))),*/
                    new RelativeDistinguishedName(
                        new AttributeTypeAndValue(new ObjectIdentifier(Oids.Attribute.CN), new UTF8String(requestData.CN)))),
                new SubjectPublicKeyInfo(
                    new AlgorithmIdentifier(Oids.Algorithm.RSA),
                    new BitString(publicKeyBytes)),
                new ContextSpecific());

            var certificationRequestInfoBytes = Asn1.Encode(certificationRequestInfo);

            var rsa = new RSACryptoServiceProvider();

            rsa.ImportParameters(requestData.Key);

            var signatureBytes = rsa.SignData(certificationRequestInfoBytes, SHA256.Create());

            return(new CertificationRequest(
                       certificationRequestInfo: certificationRequestInfo,
                       signatureAlgorithm: new AlgorithmIdentifier(Oids.Algorithm.Sha256RSA),
                       signature: new BitString(signatureBytes)
                       ));
        }
예제 #2
0
 public byte[] ToDerBytes()
 {
     return(Asn1.Encode(this));
 }
예제 #3
0
        public static byte[] EncodeAsDer(CertificateRequestData requestData)
        {
            var asn1 = Encode(requestData);

            return(Asn1.Encode(asn1));
        }