GetSignatureForObject() static private method

static private GetSignatureForObject ( DerObjectIdentifier sigOid, string sigName, AsymmetricKeyParameter privateKey, SecureRandom random, Asn1Encodable ae ) : byte[]
sigOid Org.BouncyCastle.Asn1.DerObjectIdentifier
sigName string
privateKey Org.BouncyCastle.Crypto.AsymmetricKeyParameter
random Org.BouncyCastle.Security.SecureRandom
ae Org.BouncyCastle.Asn1.Asn1Encodable
return byte[]
        /// <summary>
        /// Generate an X509 certificate, based on the current issuer and subject,
        /// using the supplied source of randomness, if required.
        /// </summary>
        public IX509AttributeCertificate Generate(
            AsymmetricKeyParameter publicKey,
            SecureRandom random)
        {
            if (!extGenerator.IsEmpty)
            {
                acInfoGen.SetExtensions(extGenerator.Generate());
            }

            AttributeCertificateInfo acInfo = acInfoGen.GenerateAttributeCertificateInfo();

            Asn1EncodableVector v = new Asn1EncodableVector();

            v.Add(acInfo, sigAlgId);

            try
            {
                v.Add(new DerBitString(X509Utilities.GetSignatureForObject(sigOID, signatureAlgorithm, publicKey, random, acInfo)));

                return(new X509V2AttributeCertificate(AttributeCertificate.GetInstance(new DerSequence(v))));
            }
            catch (Exception e)
            {
                // TODO
//				throw new ExtCertificateEncodingException("constructed invalid certificate", e);
                throw new CertificateEncodingException("constructed invalid certificate", e);
            }
        }
        /// <summary>
        /// Generate an X509Certificate using your own SecureRandom.
        /// </summary>
        /// <param name="privateKey">The private key of the issuer that is signing this certificate.</param>
        /// <param name="random">You Secure Random instance.</param>
        /// <returns>An X509Certificate.</returns>
        public X509Certificate Generate(
            IAsymmetricKeyParameter privateKey,
            SecureRandom random)
        {
            TbsCertificateStructure tbsCert = GenerateTbsCert();

            byte[] signature;

            try
            {
                signature = X509Utilities.GetSignatureForObject(
                    sigOid, signatureAlgorithm, privateKey, random, tbsCert);
            }
            catch (Exception e)
            {
                // TODO
//				throw new ExtCertificateEncodingException("exception encoding TBS cert", e);
                throw new CertificateEncodingException("exception encoding TBS cert", e);
            }

            try
            {
                return(GenerateJcaObject(tbsCert, signature));
            }
            catch (CertificateParsingException e)
            {
                // TODO
                // throw new ExtCertificateEncodingException("exception producing certificate object", e);
                throw new CertificateEncodingException("exception producing certificate object", e);
            }
        }
Exemplo n.º 3
0
        public X509Certificate Generate(AsymmetricKeyParameter privateKey, SecureRandom random)
        {
            TbsCertificateStructure tbsCertificateStructure = this.tbsGen.GenerateTbsCertificate();

            byte[] signatureForObject;
            try
            {
                signatureForObject = X509Utilities.GetSignatureForObject(this.sigOID, this.signatureAlgorithm, privateKey, random, tbsCertificateStructure);
            }
            catch (Exception e)
            {
                throw new CertificateEncodingException("exception encoding TBS cert", e);
            }
            X509Certificate result;

            try
            {
                result = this.GenerateJcaObject(tbsCertificateStructure, signatureForObject);
            }
            catch (CertificateParsingException e2)
            {
                throw new CertificateEncodingException("exception producing certificate object", e2);
            }
            return(result);
        }
        public IX509AttributeCertificate Generate(AsymmetricKeyParameter publicKey, SecureRandom random)
        {
            if (!this.extGenerator.IsEmpty)
            {
                this.acInfoGen.SetExtensions(this.extGenerator.Generate());
            }
            AttributeCertificateInfo attributeCertificateInfo = this.acInfoGen.GenerateAttributeCertificateInfo();
            Asn1EncodableVector      asn1EncodableVector      = new Asn1EncodableVector(new Asn1Encodable[0]);

            asn1EncodableVector.Add(new Asn1Encodable[]
            {
                attributeCertificateInfo,
                this.sigAlgId
            });
            IX509AttributeCertificate result;

            try
            {
                asn1EncodableVector.Add(new Asn1Encodable[]
                {
                    new DerBitString(X509Utilities.GetSignatureForObject(this.sigOID, this.signatureAlgorithm, publicKey, random, attributeCertificateInfo))
                });
                result = new X509V2AttributeCertificate(AttributeCertificate.GetInstance(new DerSequence(asn1EncodableVector)));
            }
            catch (Exception e)
            {
                throw new CertificateEncodingException("constructed invalid certificate", e);
            }
            return(result);
        }
Exemplo n.º 5
0
        public X509Crl Generate(AsymmetricKeyParameter privateKey, SecureRandom random)
        {
            TbsCertificateList tbsCertificateList = this.GenerateCertList();

            byte[] signatureForObject;
            try
            {
                signatureForObject = X509Utilities.GetSignatureForObject(this.sigOID, this.signatureAlgorithm, privateKey, random, tbsCertificateList);
            }
            catch (IOException e)
            {
                throw new CrlException("cannot generate CRL encoding", e);
            }
            return(this.GenerateJcaObject(tbsCertificateList, signatureForObject));
        }
        /// <summary>Generate an X509 CRL, based on the current issuer and subject.</summary>
        /// <param name="privateKey">The key used for signing.</param>
        /// <param name="random">A user-defined source of randomness.</param>
        public X509Crl Generate(
            IAsymmetricKeyParameter privateKey,
            SecureRandom random)
        {
            TbsCertificateList tbsCrl = GenerateCertList();

            byte[] signature;

            try
            {
                signature = X509Utilities.GetSignatureForObject(
                    sigOID, signatureAlgorithm, privateKey, random, tbsCrl);
            }
            catch (IOException e)
            {
                // TODO
//				throw new ExtCrlException("cannot generate CRL encoding", e);
                throw new CrlException("cannot generate CRL encoding", e);
            }

            return(GenerateJcaObject(tbsCrl, signature));
        }