X509CertificatePair.cs :  » PDF » iTextSharp » Org » BouncyCastle » X509 » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » PDF » iTextSharp 
iTextSharp » Org » BouncyCastle » X509 » X509CertificatePair.cs
using System;

using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Security.Certificates;
using Org.BouncyCastle.Utilities;

namespace Org.BouncyCastle.X509{
  /// <remarks>
  /// This class contains a cross certificate pair. Cross certificates pairs may
  /// contain two cross signed certificates from two CAs. A certificate from the
  /// other CA to this CA is contained in the forward certificate, the certificate
  /// from this CA to the other CA is contained in the reverse certificate.
  /// </remarks>
  public class X509CertificatePair
  {
    private readonly X509Certificate forward;
    private readonly X509Certificate reverse;

    /// <summary>Constructor</summary>
    /// <param name="forward">Certificate from the other CA to this CA.</param>
    /// <param name="reverse">Certificate from this CA to the other CA.</param>
    public X509CertificatePair(
      X509Certificate  forward,
      X509Certificate  reverse)
    {
      this.forward = forward;
      this.reverse = reverse;
    }

    /// <summary>Constructor from a ASN.1 CertificatePair structure.</summary>
    /// <param name="pair">The <c>CertificatePair</c> ASN.1 object.</param>
    public X509CertificatePair(
      CertificatePair pair)
    {
      if (pair.Forward != null)
      {
        this.forward = new X509Certificate(pair.Forward);
      }
      if (pair.Reverse != null)
      {
        this.reverse = new X509Certificate(pair.Reverse);
      }
    }

    public byte[] GetEncoded()
    {
      try
      {
        X509CertificateStructure f = null, r = null;

        if (forward != null)
        {
          f = X509CertificateStructure.GetInstance(
            Asn1Object.FromByteArray(forward.GetEncoded()));
        }

        if (reverse != null)
        {
          r = X509CertificateStructure.GetInstance(
            Asn1Object.FromByteArray(reverse.GetEncoded()));
        }

        return new CertificatePair(f, r).GetDerEncoded();
      }
      catch (Exception e)
      {
        // TODO
//        throw new ExtCertificateEncodingException(e.toString(), e);
        throw new CertificateEncodingException(e.Message, e);
      }
    }

    /// <summary>Returns the certificate from the other CA to this CA.</summary>
    public X509Certificate Forward
    {
      get { return forward; }
    }

    /// <summary>Returns the certificate from this CA to the other CA.</summary>
    public X509Certificate Reverse
    {
      get { return reverse; }
    }

    public override bool Equals(
      object obj)
    {
      if (obj == this)
        return true;

      X509CertificatePair other = obj as X509CertificatePair;

      if (other == null)
        return false;

      return Platform.Equals(this.forward, other.forward)
        && Platform.Equals(this.reverse, other.reverse);
    }

    public override int GetHashCode()
    {
      int hash = -1;
      if (forward != null)
      {
        hash ^= forward.GetHashCode();
      }
      if (reverse != null)
      {
        hash *= 17;
        hash ^= reverse.GetHashCode();
      }
      return hash;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.