ECKeyParameters.cs :  » PDF » iTextSharp » Org » BouncyCastle » Crypto » Parameters » 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 » Crypto » Parameters » ECKeyParameters.cs
using System;
using System.Globalization;

using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.CryptoPro;
using Org.BouncyCastle.Asn1.X9;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Security;

namespace Org.BouncyCastle.Crypto.Parameters{
    public abstract class ECKeyParameters
    : AsymmetricKeyParameter
    {
    private readonly string algorithm;
    private readonly ECDomainParameters parameters;
    private readonly DerObjectIdentifier publicKeyParamSet;

    protected ECKeyParameters(
      string        algorithm,
            bool        isPrivate,
            ECDomainParameters  parameters)
      : base(isPrivate)
        {
      if (algorithm == null)
        throw new ArgumentNullException("algorithm");
      if (parameters == null)
        throw new ArgumentNullException("parameters");

      this.algorithm = VerifyAlgorithmName(algorithm);
      this.parameters = parameters;
        }

    protected ECKeyParameters(
      string        algorithm,
      bool        isPrivate,
      DerObjectIdentifier  publicKeyParamSet)
      : base(isPrivate)
    {
      if (algorithm == null)
        throw new ArgumentNullException("algorithm");
      if (publicKeyParamSet == null)
        throw new ArgumentNullException("publicKeyParamSet");

      this.algorithm = VerifyAlgorithmName(algorithm);
      this.parameters = LookupParameters(publicKeyParamSet);
      this.publicKeyParamSet = publicKeyParamSet;
    }

    public string AlgorithmName
    {
      get { return algorithm; }
    }

    public ECDomainParameters Parameters
        {
      get { return parameters; }
        }

    public DerObjectIdentifier PublicKeyParamSet
    {
      get { return publicKeyParamSet; }
    }

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

      ECDomainParameters other = obj as ECDomainParameters;

      if (other == null)
        return false;

      return Equals(other);
    }

    protected bool Equals(
      ECKeyParameters other)
    {
      return parameters.Equals(other.parameters) && base.Equals(other);
    }

    public override int GetHashCode()
    {
      return parameters.GetHashCode() ^ base.GetHashCode();
    }

    internal ECKeyGenerationParameters CreateKeyGenerationParameters(
      SecureRandom random)
    {
      if (publicKeyParamSet != null)
      {
        return new ECKeyGenerationParameters(publicKeyParamSet, random);
      }

      return new ECKeyGenerationParameters(parameters, random);
    }

    private string VerifyAlgorithmName(
      string algorithm)
    {
      string upper = algorithm.ToUpper(CultureInfo.InvariantCulture);

      switch (upper)
      {
        case "EC":
        case "ECDSA":
        case "ECDH":
        case "ECDHC":
        case "ECGOST3410":
        case "ECMQV":
          break;
        default:
          throw new ArgumentException("unrecognised algorithm: " + algorithm, "algorithm");
      }

      return upper;
    }

    internal static ECDomainParameters LookupParameters(
      DerObjectIdentifier publicKeyParamSet)
    {
      if (publicKeyParamSet == null)
        throw new ArgumentNullException("publicKeyParamSet");

      ECDomainParameters p = ECGost3410NamedCurves.GetByOid(publicKeyParamSet);

      if (p == null)
      {
        X9ECParameters x9 = ECKeyPairGenerator.FindECCurveByOid(publicKeyParamSet);

        if (x9 == null)
        {
          throw new ArgumentException("OID is not a valid public key parameter set", "publicKeyParamSet");
        }

        p = new ECDomainParameters(x9.Curve, x9.G, x9.N, x9.H, x9.GetSeed());
      }

      return p;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.