/// <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);
            }
        }
        /// <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);
            }
        }
예제 #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);
        }
예제 #5
0
 public void SetSignatureAlgorithm(string signatureAlgorithm)
 {
     this.signatureAlgorithm = signatureAlgorithm;
     try
     {
         this.sigOID = X509Utilities.GetAlgorithmOid(signatureAlgorithm);
     }
     catch (Exception innerException)
     {
         throw new ArgumentException("Unknown signature type requested", innerException);
     }
     this.sigAlgId = X509Utilities.GetSigAlgID(this.sigOID, signatureAlgorithm);
     this.tbsGen.SetSignature(this.sigAlgId);
 }
예제 #6
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));
        }
예제 #7
0
 public void SetSignatureAlgorithm(string signatureAlgorithm)
 {
     //IL_001b: Unknown result type (might be due to invalid IL or missing references)
     this.signatureAlgorithm = signatureAlgorithm;
     try
     {
         sigOID = X509Utilities.GetAlgorithmOid(signatureAlgorithm);
     }
     catch (global::System.Exception)
     {
         throw new ArgumentException("Unknown signature type requested");
     }
     sigAlgId = X509Utilities.GetSigAlgID(sigOID, signatureAlgorithm);
     acInfoGen.SetSignature(sigAlgId);
 }
예제 #8
0
        public void SetSignatureAlgorithm(
            string signatureAlgorithm)
        {
            this.signatureAlgorithm = signatureAlgorithm;

            try
            {
                sigOid = X509Utilities.GetAlgorithmOid(signatureAlgorithm);
            }
            catch (Exception)
            {
                throw new ArgumentException("Unknown signature type requested: " + signatureAlgorithm);
            }

            sigAlgId = X509Utilities.GetSigAlgID(sigOid, signatureAlgorithm);

            tbsGen.SetSignature(sigAlgId);
        }
        /// <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));
        }
예제 #10
0
        static X509Utilities()
        {
            X509Utilities.algorithms = Platform.CreateHashtable();
            X509Utilities.exParams   = Platform.CreateHashtable();
            X509Utilities.noParams   = new HashSet();
            X509Utilities.algorithms.Add("MD2WITHRSAENCRYPTION", PkcsObjectIdentifiers.MD2WithRsaEncryption);
            X509Utilities.algorithms.Add("MD2WITHRSA", PkcsObjectIdentifiers.MD2WithRsaEncryption);
            X509Utilities.algorithms.Add("MD5WITHRSAENCRYPTION", PkcsObjectIdentifiers.MD5WithRsaEncryption);
            X509Utilities.algorithms.Add("MD5WITHRSA", PkcsObjectIdentifiers.MD5WithRsaEncryption);
            X509Utilities.algorithms.Add("SHA1WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha1WithRsaEncryption);
            X509Utilities.algorithms.Add("SHA1WITHRSA", PkcsObjectIdentifiers.Sha1WithRsaEncryption);
            X509Utilities.algorithms.Add("SHA224WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha224WithRsaEncryption);
            X509Utilities.algorithms.Add("SHA224WITHRSA", PkcsObjectIdentifiers.Sha224WithRsaEncryption);
            X509Utilities.algorithms.Add("SHA256WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha256WithRsaEncryption);
            X509Utilities.algorithms.Add("SHA256WITHRSA", PkcsObjectIdentifiers.Sha256WithRsaEncryption);
            X509Utilities.algorithms.Add("SHA384WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha384WithRsaEncryption);
            X509Utilities.algorithms.Add("SHA384WITHRSA", PkcsObjectIdentifiers.Sha384WithRsaEncryption);
            X509Utilities.algorithms.Add("SHA512WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha512WithRsaEncryption);
            X509Utilities.algorithms.Add("SHA512WITHRSA", PkcsObjectIdentifiers.Sha512WithRsaEncryption);
            X509Utilities.algorithms.Add("SHA1WITHRSAANDMGF1", PkcsObjectIdentifiers.IdRsassaPss);
            X509Utilities.algorithms.Add("SHA224WITHRSAANDMGF1", PkcsObjectIdentifiers.IdRsassaPss);
            X509Utilities.algorithms.Add("SHA256WITHRSAANDMGF1", PkcsObjectIdentifiers.IdRsassaPss);
            X509Utilities.algorithms.Add("SHA384WITHRSAANDMGF1", PkcsObjectIdentifiers.IdRsassaPss);
            X509Utilities.algorithms.Add("SHA512WITHRSAANDMGF1", PkcsObjectIdentifiers.IdRsassaPss);
            X509Utilities.algorithms.Add("RIPEMD160WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160);
            X509Utilities.algorithms.Add("RIPEMD160WITHRSA", TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160);
            X509Utilities.algorithms.Add("RIPEMD128WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128);
            X509Utilities.algorithms.Add("RIPEMD128WITHRSA", TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128);
            X509Utilities.algorithms.Add("RIPEMD256WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256);
            X509Utilities.algorithms.Add("RIPEMD256WITHRSA", TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256);
            X509Utilities.algorithms.Add("SHA1WITHDSA", X9ObjectIdentifiers.IdDsaWithSha1);
            X509Utilities.algorithms.Add("DSAWITHSHA1", X9ObjectIdentifiers.IdDsaWithSha1);
            X509Utilities.algorithms.Add("SHA224WITHDSA", NistObjectIdentifiers.DsaWithSha224);
            X509Utilities.algorithms.Add("SHA256WITHDSA", NistObjectIdentifiers.DsaWithSha256);
            X509Utilities.algorithms.Add("SHA384WITHDSA", NistObjectIdentifiers.DsaWithSha384);
            X509Utilities.algorithms.Add("SHA512WITHDSA", NistObjectIdentifiers.DsaWithSha512);
            X509Utilities.algorithms.Add("SHA1WITHECDSA", X9ObjectIdentifiers.ECDsaWithSha1);
            X509Utilities.algorithms.Add("ECDSAWITHSHA1", X9ObjectIdentifiers.ECDsaWithSha1);
            X509Utilities.algorithms.Add("SHA224WITHECDSA", X9ObjectIdentifiers.ECDsaWithSha224);
            X509Utilities.algorithms.Add("SHA256WITHECDSA", X9ObjectIdentifiers.ECDsaWithSha256);
            X509Utilities.algorithms.Add("SHA384WITHECDSA", X9ObjectIdentifiers.ECDsaWithSha384);
            X509Utilities.algorithms.Add("SHA512WITHECDSA", X9ObjectIdentifiers.ECDsaWithSha512);
            X509Utilities.algorithms.Add("GOST3411WITHGOST3410", CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94);
            X509Utilities.algorithms.Add("GOST3411WITHGOST3410-94", CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94);
            X509Utilities.algorithms.Add("GOST3411WITHECGOST3410", CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001);
            X509Utilities.algorithms.Add("GOST3411WITHECGOST3410-2001", CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001);
            X509Utilities.algorithms.Add("GOST3411WITHGOST3410-2001", CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001);
            X509Utilities.noParams.Add(X9ObjectIdentifiers.ECDsaWithSha1);
            X509Utilities.noParams.Add(X9ObjectIdentifiers.ECDsaWithSha224);
            X509Utilities.noParams.Add(X9ObjectIdentifiers.ECDsaWithSha256);
            X509Utilities.noParams.Add(X9ObjectIdentifiers.ECDsaWithSha384);
            X509Utilities.noParams.Add(X9ObjectIdentifiers.ECDsaWithSha512);
            X509Utilities.noParams.Add(X9ObjectIdentifiers.IdDsaWithSha1);
            X509Utilities.noParams.Add(NistObjectIdentifiers.DsaWithSha224);
            X509Utilities.noParams.Add(NistObjectIdentifiers.DsaWithSha256);
            X509Utilities.noParams.Add(NistObjectIdentifiers.DsaWithSha384);
            X509Utilities.noParams.Add(NistObjectIdentifiers.DsaWithSha512);
            X509Utilities.noParams.Add(CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94);
            X509Utilities.noParams.Add(CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001);
            AlgorithmIdentifier hashAlgId = new AlgorithmIdentifier(OiwObjectIdentifiers.IdSha1, DerNull.Instance);

            X509Utilities.exParams.Add("SHA1WITHRSAANDMGF1", X509Utilities.CreatePssParams(hashAlgId, 20));
            AlgorithmIdentifier hashAlgId2 = new AlgorithmIdentifier(NistObjectIdentifiers.IdSha224, DerNull.Instance);

            X509Utilities.exParams.Add("SHA224WITHRSAANDMGF1", X509Utilities.CreatePssParams(hashAlgId2, 28));
            AlgorithmIdentifier hashAlgId3 = new AlgorithmIdentifier(NistObjectIdentifiers.IdSha256, DerNull.Instance);

            X509Utilities.exParams.Add("SHA256WITHRSAANDMGF1", X509Utilities.CreatePssParams(hashAlgId3, 32));
            AlgorithmIdentifier hashAlgId4 = new AlgorithmIdentifier(NistObjectIdentifiers.IdSha384, DerNull.Instance);

            X509Utilities.exParams.Add("SHA384WITHRSAANDMGF1", X509Utilities.CreatePssParams(hashAlgId4, 48));
            AlgorithmIdentifier hashAlgId5 = new AlgorithmIdentifier(NistObjectIdentifiers.IdSha512, DerNull.Instance);

            X509Utilities.exParams.Add("SHA512WITHRSAANDMGF1", X509Utilities.CreatePssParams(hashAlgId5, 64));
        }