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

CA认证

开发平台:

Java

  1. package org.bouncycastle.asn1.x509;
  2. import org.bouncycastle.asn1.*;
  3. import org.bouncycastle.asn1.pkcs.*;
  4. /**
  5.  * an X509Certificate structure.
  6.  * <pre>
  7.  *  Certificate ::= SEQUENCE {
  8.  *      tbsCertificate          TBSCertificate,
  9.  *      signatureAlgorithm      AlgorithmIdentifier,
  10.  *      signature               BIT STRING
  11.  *  }
  12.  * </pre>
  13.  */
  14. public class X509CertificateStructure
  15.     implements DEREncodable, X509ObjectIdentifiers, PKCSObjectIdentifiers
  16. {
  17.     ASN1Sequence  seq;
  18.     TBSCertificateStructure tbsCert;
  19.     AlgorithmIdentifier     sigAlgId;
  20.     DERBitString            sig;
  21.     public static X509CertificateStructure getInstance(
  22.         ASN1TaggedObject obj,
  23.         boolean          explicit)
  24.     {
  25.         return getInstance(ASN1Sequence.getInstance(obj, explicit));
  26.     }
  27.     public static X509CertificateStructure getInstance(
  28.         Object  obj)
  29.     {
  30.         if (obj instanceof X509CertificateStructure)
  31.         {
  32.             return (X509CertificateStructure)obj;
  33.         }
  34.         else if (obj instanceof ASN1Sequence)
  35.         {
  36.             return new X509CertificateStructure((ASN1Sequence)obj);
  37.         }
  38.         throw new IllegalArgumentException("unknown object in factory");
  39.     }
  40.     public X509CertificateStructure(
  41.         ASN1Sequence  seq)
  42.     {
  43.         this.seq = seq;
  44.         //
  45.         // correct x509 certficate
  46.         //
  47.         if (seq.size() == 3)
  48.         {
  49.             tbsCert = TBSCertificateStructure.getInstance(seq.getObjectAt(0));
  50.             sigAlgId = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));
  51.             sig = (DERBitString)seq.getObjectAt(2);
  52.         }
  53.     }
  54.     public TBSCertificateStructure getTBSCertificate()
  55.     {
  56.         return tbsCert;
  57.     }
  58.     public int getVersion()
  59.     {
  60.         return tbsCert.getVersion();
  61.     }
  62.     public DERInteger getSerialNumber()
  63.     {
  64.         return tbsCert.getSerialNumber();
  65.     }
  66.     public X509Name getIssuer()
  67.     {
  68.         return tbsCert.getIssuer();
  69.     }
  70.     public Time getStartDate()
  71.     {
  72.         return tbsCert.getStartDate();
  73.     }
  74.     public Time getEndDate()
  75.     {
  76.         return tbsCert.getEndDate();
  77.     }
  78.     public X509Name getSubject()
  79.     {
  80.         return tbsCert.getSubject();
  81.     }
  82.     public SubjectPublicKeyInfo getSubjectPublicKeyInfo()
  83.     {
  84.         return tbsCert.getSubjectPublicKeyInfo();
  85.     }
  86.     public AlgorithmIdentifier getSignatureAlgorithm()
  87.     {
  88.         return sigAlgId;
  89.     }
  90.     public DERBitString getSignature()
  91.     {
  92.         return sig;
  93.     }
  94.     public DERObject getDERObject()
  95.     {
  96.         return seq;
  97.     }
  98.     // 张荣华 2003.0701 添加了生成证书的函数
  99.     public DERObject generateX509Cert(
  100.             TBSCertificateStructure tbsCert,
  101.             AlgorithmIdentifier     sigAlgId,
  102.             DERBitString            sig)
  103.     {
  104.         ASN1EncodableVector  v = new ASN1EncodableVector();
  105.         v.add(tbsCert);
  106.         v.add(sigAlgId);
  107.         v.add(sig);
  108.         return new DERSequence(v);
  109.     }
  110. }