Brunet.Security.CertificateHandler.AddCACertificate C# (CSharp) Method

AddCACertificate() public method

Adds CA certificate to this CH.
public AddCACertificate ( Mono.Security.X509.X509Certificate cert ) : bool
cert Mono.Security.X509.X509Certificate
return bool
    virtual public bool AddCACertificate(X509Certificate cert) {
      Brunet.Util.MemBlock sn = Brunet.Util.MemBlock.Reference(cert.SerialNumber);
      lock(_sync) {
        _cas[sn] = cert;
        _supported_cas.Add(sn);
      }
      return true;
    }

Usage Example

        public void ValidityTest()
        {
            CertificateHandler       ch  = new CertificateHandler();
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(512);

            byte[] blob = rsa.ExportCspBlob(false);
            RSACryptoServiceProvider rsa_pub = new RSACryptoServiceProvider();

            rsa_pub.ImportCspBlob(blob);
            string           ID = "brunet:node:PXYSWDL5SZDHDDXJKZCLFENOP2KZDMBU";
            CertificateMaker cm = new CertificateMaker("US", "UFL", "ACIS", "David Wolinsky",
                                                       "*****@*****.**", rsa_pub, ID);
            Certificate cert_0 = cm.Sign(cm, rsa);

            ch.AddSignedCertificate(cert_0.X509);
            ch.AddCACertificate(cert_0.X509);
            rsa = new RSACryptoServiceProvider(1024);
            rsa_pub.ImportCspBlob(rsa.ExportCspBlob(false));
            cm = new CertificateMaker("US", "UFL", "ACIS", "David Wolinsky",
                                      "*****@*****.**", rsa_pub, ID);
            Certificate cert_1 = cm.Sign(cm, rsa);

            Assert.IsTrue(ch.Verify(cert_0.X509, null, ID), "Valid");
            bool success = false;

            try {
                success = ch.Verify(cert_1.X509, null, ID);
            } catch { }
            Assert.IsTrue(!success, "Valid cert2");
        }
All Usage Examples Of Brunet.Security.CertificateHandler::AddCACertificate