Pkcs10CertificationRequestDelaySigned.cs :  » PDF » iTextSharp » Org » BouncyCastle » 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 » Pkcs » Pkcs10CertificationRequestDelaySigned.cs
using System;
using System.Collections;
using System.Globalization;
using System.IO;
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.CryptoPro;
using Org.BouncyCastle.Asn1.Nist;
using Org.BouncyCastle.Asn1.Oiw;
using Org.BouncyCastle.Asn1.Pkcs;
using Org.BouncyCastle.Asn1.TeleTrust;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Asn1.X9;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Utilities;
using Org.BouncyCastle.Utilities.Collections;
using Org.BouncyCastle.X509;
namespace Org.BouncyCastle.Pkcs{
  /// <remarks>
  /// A class for creating and verifying Pkcs10 Certification requests (this is an extension on <see cref="Pkcs10CertificationRequest"/>).
  /// The requests are made using delay signing. This is useful for situations where
  /// the private key is in another environment and not directly accessible (e.g. HSM)
  /// So the first step creates the request, then the signing is done outside this
  /// object and the signature is then used to complete the request.
  /// </remarks>
  /// <code>
  /// CertificationRequest ::= Sequence {
  ///   certificationRequestInfo  CertificationRequestInfo,
  ///   signatureAlgorithm        AlgorithmIdentifier{{ SignatureAlgorithms }},
  ///   signature                 BIT STRING
  /// }
  ///
  /// CertificationRequestInfo ::= Sequence {
  ///   version             Integer { v1(0) } (v1,...),
  ///   subject             Name,
  ///   subjectPKInfo   SubjectPublicKeyInfo{{ PKInfoAlgorithms }},
  ///   attributes          [0] Attributes{{ CRIAttributes }}
  ///  }
  ///
  ///  Attributes { ATTRIBUTE:IOSet } ::= Set OF Attr{{ IOSet }}
  ///
  ///  Attr { ATTRIBUTE:IOSet } ::= Sequence {
  ///    type    ATTRIBUTE.&amp;id({IOSet}),
  ///    values  Set SIZE(1..MAX) OF ATTRIBUTE.&amp;Type({IOSet}{\@type})
  ///  }
  /// </code>
  /// see <a href="http://www.rsasecurity.com/rsalabs/node.asp?id=2132"/>
  public class Pkcs10CertificationRequestDelaySigned : Pkcs10CertificationRequest
  {
    protected Pkcs10CertificationRequestDelaySigned()
      : base()
    {
    }
    public Pkcs10CertificationRequestDelaySigned(
      byte[] encoded)
      : base(encoded)
    {
    }
    public Pkcs10CertificationRequestDelaySigned(
      Asn1Sequence seq)
      : base(seq)
    {
    }
    public Pkcs10CertificationRequestDelaySigned(
      Stream input)
      : base(input)
    {
    }
    public Pkcs10CertificationRequestDelaySigned(
      string          signatureAlgorithm,
      X509Name        subject,
      AsymmetricKeyParameter  publicKey,
      Asn1Set          attributes,
      AsymmetricKeyParameter  signingKey)
      : base(signatureAlgorithm, subject, publicKey, attributes, signingKey)
    {
    }
    /// <summary>
    /// Instantiate a Pkcs10CertificationRequest object with the necessary credentials.
    /// </summary>
    /// <param name="signatureAlgorithm">Name of Sig Alg.</param>
    /// <param name="subject">X509Name of subject eg OU="My unit." O="My Organisatioin" C="au" </param>
    /// <param name="publicKey">Public Key to be included in cert reqest.</param>
    /// <param name="attributes">ASN1Set of Attributes.</param>
    /// <remarks>
    /// After the object is constructed use the <see cref="GetDataToSign"/> and finally the <see cref="SignRequest"/> methods to finalize the
    /// request.
    /// </remarks>
    public Pkcs10CertificationRequestDelaySigned(
      string          signatureAlgorithm,
      X509Name        subject,
      AsymmetricKeyParameter  publicKey,
      Asn1Set          attributes)
    {
      if (signatureAlgorithm == null)
        throw new ArgumentNullException("signatureAlgorithm");
      if (subject == null)
        throw new ArgumentNullException("subject");
      if (publicKey == null)
        throw new ArgumentNullException("publicKey");
      if (publicKey.IsPrivate)
        throw new ArgumentException("expected public key", "publicKey");
//      DerObjectIdentifier sigOid = SignerUtilities.GetObjectIdentifier(signatureAlgorithm);
      string algorithmName = signatureAlgorithm.ToUpper(CultureInfo.InvariantCulture);
      DerObjectIdentifier sigOid = (DerObjectIdentifier) algorithms[algorithmName];
      if (sigOid == null)
        throw new ArgumentException("Unknown signature type requested");
      if (noParams.Contains(sigOid))
      {
        this.sigAlgId = new AlgorithmIdentifier(sigOid);
      }
      else if (exParams.ContainsKey(algorithmName))
      {
        this.sigAlgId = new AlgorithmIdentifier(sigOid, (Asn1Encodable) exParams[algorithmName]);
      }
      else
      {
        this.sigAlgId = new AlgorithmIdentifier(sigOid, null);
      }
      SubjectPublicKeyInfo pubInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(publicKey);
      this.reqInfo = new CertificationRequestInfo(subject, pubInfo, attributes);
    }
    public byte[] GetDataToSign()
    {
      return reqInfo.GetDerEncoded();
    }
    public void SignRequest(byte[] signedData)
    {
      //build the signature from the signed data
      sigBits = new DerBitString(signedData);
    }
    public void SignRequest(DerBitString signedData)
    {
      //build the signature from the signed data
      sigBits = signedData;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.