SignerInfo.java
上传用户:lior1029
上传日期:2013-05-07
资源大小:209k
文件大小:5k
源码类别:

CA认证

开发平台:

Java

  1. package org.bouncycastle.asn1.pkcs;
  2. import java.util.Enumeration;
  3. import org.bouncycastle.asn1.*;
  4. import org.bouncycastle.asn1.x509.*;
  5. /**
  6.  * a PKCS#7 signer info object.
  7.  */
  8. public class SignerInfo
  9.     implements DEREncodable
  10. {
  11.     private DERInteger              version;
  12.     private IssuerAndSerialNumber   issuerAndSerialNumber;
  13.     private AlgorithmIdentifier     digAlgorithm;
  14.     private ASN1Set                 authenticatedAttributes;
  15.     private AlgorithmIdentifier     digEncryptionAlgorithm;
  16.     private ASN1OctetString         encryptedDigest;
  17.     private ASN1Set                 unauthenticatedAttributes;
  18.     public static SignerInfo getInstance(
  19.         Object  o)
  20.     {
  21.         if (o instanceof SignerInfo)
  22.         {
  23.             return (SignerInfo)o;
  24.         }
  25.         else if (o instanceof ASN1Sequence)
  26.         {
  27.             return new SignerInfo((ASN1Sequence)o);
  28.         }
  29.         throw new IllegalArgumentException("unknown object in factory");
  30.     }
  31.     public SignerInfo(
  32.         DERInteger              version,
  33.         IssuerAndSerialNumber   issuerAndSerialNumber,
  34.         AlgorithmIdentifier     digAlgorithm,
  35.         ASN1Set                 authenticatedAttributes,
  36.         AlgorithmIdentifier     digEncryptionAlgorithm,
  37.         ASN1OctetString         encryptedDigest,
  38.         ASN1Set                 unauthenticatedAttributes)
  39.     {
  40.         this.version = version;
  41.         this.issuerAndSerialNumber = issuerAndSerialNumber;
  42.         this.digAlgorithm = digAlgorithm;
  43.         this.authenticatedAttributes = authenticatedAttributes;
  44.         this.digEncryptionAlgorithm = digEncryptionAlgorithm;
  45.         this.encryptedDigest = encryptedDigest;
  46.         this.unauthenticatedAttributes = unauthenticatedAttributes;
  47.     }
  48.     public SignerInfo(
  49.         ASN1Sequence seq)
  50.     {
  51.         Enumeration     e = seq.getObjects();
  52.         version = (DERInteger)e.nextElement();
  53.         issuerAndSerialNumber = IssuerAndSerialNumber.getInstance(e.nextElement());
  54.         digAlgorithm = AlgorithmIdentifier.getInstance(e.nextElement());
  55.         Object obj = e.nextElement();
  56.         if (obj instanceof ASN1TaggedObject)
  57.         {
  58.             authenticatedAttributes = ASN1Set.getInstance((ASN1TaggedObject)obj, false);
  59.             digEncryptionAlgorithm = AlgorithmIdentifier.getInstance(e.nextElement());
  60.         }
  61.         else
  62.         {
  63.             authenticatedAttributes = null;
  64.             digEncryptionAlgorithm = AlgorithmIdentifier.getInstance(obj);
  65.         }
  66.         encryptedDigest = DEROctetString.getInstance(e.nextElement());
  67.         if (e.hasMoreElements())
  68.         {
  69.             unauthenticatedAttributes = ASN1Set.getInstance((ASN1TaggedObject)e.nextElement(), false);
  70.         }
  71.         else
  72.         {
  73.             unauthenticatedAttributes = null;
  74.         }
  75.     }
  76.     public DERInteger getVersion()
  77.     {
  78.         return version;
  79.     }
  80.     public IssuerAndSerialNumber getIssuerAndSerialNumber()
  81.     {
  82.         return issuerAndSerialNumber;
  83.     }
  84.     public ASN1Set getAuthenticatedAttributes()
  85.     {
  86.         return authenticatedAttributes;
  87.     }
  88.     public AlgorithmIdentifier getDigestAlgorithm()
  89.     {
  90.         return digAlgorithm;
  91.     }
  92.     public ASN1OctetString getEncryptedDigest()
  93.     {
  94.         return encryptedDigest;
  95.     }
  96.     public AlgorithmIdentifier getDigestEncryptionAlgorithm()
  97.     {
  98.         return digEncryptionAlgorithm;
  99.     }
  100.     public ASN1Set getUnauthenticatedAttributes()
  101.     {
  102.         return unauthenticatedAttributes;
  103.     }
  104.     /**
  105.      * <pre>
  106.      *  SignerInfo ::= SEQUENCE {
  107.      *      version Version,
  108.      *      issuerAndSerialNumber IssuerAndSerialNumber,
  109.      *      digestAlgorithm DigestAlgorithmIdentifier,
  110.      *      authenticatedAttributes [0] IMPLICIT Attributes OPTIONAL,
  111.      *      digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier,
  112.      *      encryptedDigest EncryptedDigest,
  113.      *      unauthenticatedAttributes [1] IMPLICIT Attributes OPTIONAL
  114.      *  }
  115.      *
  116.      *  EncryptedDigest ::= OCTET STRING
  117.      *
  118.      *  DigestAlgorithmIdentifier ::= AlgorithmIdentifier
  119.      *
  120.      *  DigestEncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
  121.      * </pre>
  122.      */
  123.     public DERObject getDERObject()
  124.     {
  125.         ASN1EncodableVector v = new ASN1EncodableVector();
  126.         v.add(version);
  127.         v.add(issuerAndSerialNumber);
  128.         v.add(digAlgorithm);
  129.         if (authenticatedAttributes != null)
  130.         {
  131.             v.add(new DERTaggedObject(false, 0, authenticatedAttributes));
  132.         }
  133.         v.add(digEncryptionAlgorithm);
  134.         v.add(encryptedDigest);
  135.         if (unauthenticatedAttributes != null)
  136.         {
  137.             v.add(new DERTaggedObject(false, 1, unauthenticatedAttributes));
  138.         }
  139.         return new DERSequence(v);
  140.     }
  141. }