RSAPrivateKeyStructure.cs :  » PDF » iTextSharp » Org » BouncyCastle » Asn1 » Pkcs » 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 » Asn1 » Pkcs » RSAPrivateKeyStructure.cs
using System;
using System.Collections;

using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Math;

namespace Org.BouncyCastle.Asn1.Pkcs{
    public class RsaPrivateKeyStructure
        : Asn1Encodable
    {
        private readonly BigInteger  modulus;
        private readonly BigInteger  publicExponent;
        private readonly BigInteger  privateExponent;
        private readonly BigInteger  prime1;
        private readonly BigInteger  prime2;
        private readonly BigInteger  exponent1;
        private readonly BigInteger  exponent2;
        private readonly BigInteger  coefficient;

    public RsaPrivateKeyStructure(
            BigInteger  modulus,
            BigInteger  publicExponent,
            BigInteger  privateExponent,
            BigInteger  prime1,
            BigInteger  prime2,
            BigInteger  exponent1,
            BigInteger  exponent2,
            BigInteger  coefficient)
        {
            this.modulus = modulus;
            this.publicExponent = publicExponent;
            this.privateExponent = privateExponent;
            this.prime1 = prime1;
            this.prime2 = prime2;
            this.exponent1 = exponent1;
            this.exponent2 = exponent2;
            this.coefficient = coefficient;
        }

    public RsaPrivateKeyStructure(
            Asn1Sequence seq)
        {
      BigInteger version = ((DerInteger) seq[0]).Value;
      if (version.IntValue != 0)
                throw new ArgumentException("wrong version for RSA private key");

      modulus = ((DerInteger) seq[1]).Value;
      publicExponent = ((DerInteger) seq[2]).Value;
      privateExponent = ((DerInteger) seq[3]).Value;
      prime1 = ((DerInteger) seq[4]).Value;
      prime2 = ((DerInteger) seq[5]).Value;
      exponent1 = ((DerInteger) seq[6]).Value;
      exponent2 = ((DerInteger) seq[7]).Value;
      coefficient = ((DerInteger) seq[8]).Value;
    }

    public BigInteger Modulus
    {
      get { return modulus; }
    }

    public BigInteger PublicExponent
    {
      get { return publicExponent; }
    }

    public BigInteger PrivateExponent
    {
      get { return privateExponent; }
    }

    public BigInteger Prime1
    {
      get { return prime1; }
    }

    public BigInteger Prime2
    {
      get { return prime2; }
    }

    public BigInteger Exponent1
    {
      get { return exponent1; }
    }

    public BigInteger Exponent2
    {
      get { return exponent2; }
    }

    public BigInteger Coefficient
    {
      get { return coefficient; }
    }

    /**
         * This outputs the key in Pkcs1v2 format.
         * <pre>
         *      RsaPrivateKey ::= Sequence {
         *                          version Version,
         *                          modulus Integer, -- n
         *                          publicExponent Integer, -- e
         *                          privateExponent Integer, -- d
         *                          prime1 Integer, -- p
         *                          prime2 Integer, -- q
         *                          exponent1 Integer, -- d mod (p-1)
         *                          exponent2 Integer, -- d mod (q-1)
         *                          coefficient Integer -- (inverse of q) mod p
         *                      }
         *
         *      Version ::= Integer
         * </pre>
         * <p>This routine is written to output Pkcs1 version 0, private keys.</p>
         */
        public override Asn1Object ToAsn1Object()
        {
      return new DerSequence(
        new DerInteger(0), // version
        new DerInteger(Modulus),
        new DerInteger(PublicExponent),
        new DerInteger(PrivateExponent),
        new DerInteger(Prime1),
        new DerInteger(Prime2),
        new DerInteger(Exponent1),
        new DerInteger(Exponent2),
        new DerInteger(Coefficient));
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.