X509CertificateStructure.java
资源名称:security.rar [点击查看]
上传用户:lior1029
上传日期:2013-05-07
资源大小:209k
文件大小:3k
源码类别:
CA认证
开发平台:
Java
- package org.bouncycastle.asn1.x509;
- import org.bouncycastle.asn1.*;
- import org.bouncycastle.asn1.pkcs.*;
- /**
- * an X509Certificate structure.
- * <pre>
- * Certificate ::= SEQUENCE {
- * tbsCertificate TBSCertificate,
- * signatureAlgorithm AlgorithmIdentifier,
- * signature BIT STRING
- * }
- * </pre>
- */
- public class X509CertificateStructure
- implements DEREncodable, X509ObjectIdentifiers, PKCSObjectIdentifiers
- {
- ASN1Sequence seq;
- TBSCertificateStructure tbsCert;
- AlgorithmIdentifier sigAlgId;
- DERBitString sig;
- public static X509CertificateStructure getInstance(
- ASN1TaggedObject obj,
- boolean explicit)
- {
- return getInstance(ASN1Sequence.getInstance(obj, explicit));
- }
- public static X509CertificateStructure getInstance(
- Object obj)
- {
- if (obj instanceof X509CertificateStructure)
- {
- return (X509CertificateStructure)obj;
- }
- else if (obj instanceof ASN1Sequence)
- {
- return new X509CertificateStructure((ASN1Sequence)obj);
- }
- throw new IllegalArgumentException("unknown object in factory");
- }
- public X509CertificateStructure(
- ASN1Sequence seq)
- {
- this.seq = seq;
- //
- // correct x509 certficate
- //
- if (seq.size() == 3)
- {
- tbsCert = TBSCertificateStructure.getInstance(seq.getObjectAt(0));
- sigAlgId = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));
- sig = (DERBitString)seq.getObjectAt(2);
- }
- }
- public TBSCertificateStructure getTBSCertificate()
- {
- return tbsCert;
- }
- public int getVersion()
- {
- return tbsCert.getVersion();
- }
- public DERInteger getSerialNumber()
- {
- return tbsCert.getSerialNumber();
- }
- public X509Name getIssuer()
- {
- return tbsCert.getIssuer();
- }
- public Time getStartDate()
- {
- return tbsCert.getStartDate();
- }
- public Time getEndDate()
- {
- return tbsCert.getEndDate();
- }
- public X509Name getSubject()
- {
- return tbsCert.getSubject();
- }
- public SubjectPublicKeyInfo getSubjectPublicKeyInfo()
- {
- return tbsCert.getSubjectPublicKeyInfo();
- }
- public AlgorithmIdentifier getSignatureAlgorithm()
- {
- return sigAlgId;
- }
- public DERBitString getSignature()
- {
- return sig;
- }
- public DERObject getDERObject()
- {
- return seq;
- }
- // 张荣华 2003.0701 添加了生成证书的函数
- public DERObject generateX509Cert(
- TBSCertificateStructure tbsCert,
- AlgorithmIdentifier sigAlgId,
- DERBitString sig)
- {
- ASN1EncodableVector v = new ASN1EncodableVector();
- v.add(tbsCert);
- v.add(sigAlgId);
- v.add(sig);
- return new DERSequence(v);
- }
- }