示例#1
0
        public CertificationRequest Encode(CertificateRequestData requestData)
        {
            var publicKeyBytes = serializer.Serialize(new Sequence(new Integer(requestData.Key.Modulus), new Integer(requestData.Key.Exponent))).ToArray();

            var certificationRequestInfo = new CertificationRequestInfo(
                new Integer(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(Oid.Attribute.CN), new UTF8String(requestData.CN)))),
                new SubjectPublicKeyInfo(
                    new AlgorithmIdentifier(Oid.Algorithm.RSA),
                    new BitString(publicKeyBytes)),
                new ContextSpecific());

            var certificationRequestInfoBytes = serializer.Serialize(certificationRequestInfo).ToArray();

            var rsa = new RSACryptoServiceProvider();

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

            return(new CertificationRequest(
                       certificationRequestInfo,
                       new AlgorithmIdentifier(Oid.Algorithm.sha256RSA),
                       new BitString(signatureBytes)));
        }