Beispiel #1
0
        /// <summary>
        /// Instanciate a PKCS10CertificationRequest object with the necessary credentials.
        /// </summary>
        ///<param name="signatureAlgorithm">Name of Sig Alg.</param>
        /// <param name="subject">X509Name of subject eg OU="My unit." O="My Organisatioin" C="au" </param>
        /// <param name="key">Public Key to be included in cert reqest.</param>
        /// <param name="attributes">ASN1Set of Attributes.</param>
        /// <param name="signingKey">Matching Private key for nominated (above) public key to be used to sign the request.</param>
        public PKCS10CertificationRequest(String signatureAlgorithm,
                                          X509Name subject,
                                          AsymmetricKeyParameter key,
                                          ASN1Set attributes,
                                          AsymmetricKeyParameter signingKey)

        {
            DERObjectIdentifier sigOID = SignerUtil.getObjectIdentifier(signatureAlgorithm.ToUpper());

            if (sigOID == null)
            {
                throw new ArgumentException("Unknown signature type requested");
            }

            if (subject == null)
            {
                throw new ArgumentException("subject must not be null");
            }

            if (key == null)
            {
                throw new ArgumentException("public key must not be null");
            }



            this.sigAlgId = new AlgorithmIdentifier(sigOID, null);

            SubjectPublicKeyInfo pubInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(key);


            this.reqInfo = new CertificationRequestInfo(subject, pubInfo, attributes);

            Signer sig = null;

            // Create appropriate Signature.
            sig = SignerUtil.getSigner(sigAlgId.getObjectId());

            sig.init(true, signingKey);

            // Encode.

            MemoryStream    mStr   = new MemoryStream();
            DEROutputStream derOut = new DEROutputStream(mStr);

            derOut.writeObject(reqInfo);

            // Sign
            byte[] b = mStr.ToArray();
            sig.update(b, 0, b.Length);

            // Generate Signature.
            sigBits = new DERBitString(sig.generateSignature());
        }
Beispiel #2
0
        /// <summary>
        /// Set the signature algorithm that will be used to sign this certificate.
        /// </summary>
        /// <param name="signatureAlgorithm"></param>
        public void setSignatureAlgorithm(String signatureAlgorithm)
        {
            sigOID = SignerUtil.getObjectIdentifier(signatureAlgorithm);

            if (sigOID == null)
            {
                throw new Exception("Unknown signature type requested");
            }

            sigAlgId = new AlgorithmIdentifier(this.sigOID, new DERNull());

            tbsGen.setSignature(sigAlgId);
        }