⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timestamptoken.java

📁 进行与数字证书相关开发必须的java源码
💻 JAVA
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   TimeStampToken.java

package jit.timestamp;

import jit.asn1.*;
import jit.asn1.pkcs.PKCSObjectIdentifiers;
import jit.asn1.pkcs.pkcs7.ContentInfo;
import jit.asn1.pkcs.pkcs7.SignedData;
import jit.asn1.x509.X509CertificateStructure;
import jit.asn1parser.Parser;
import jit.asn1parser.pkcs.pkcs7.SignedDataParser;
import jit.asn1parser.x509.X509Cert;
import jit.jcrypto.*;

// Referenced classes of package jit.timestamp:
//            TSTInfo

public class TimeStampToken
{

    private final DERObjectIdentifier id_ct_TSTInfo;
    private DERObjectIdentifier hashAlgOID;
    private TSTInfo tstInfo;
    private X509Cert tsaCert;
    private DERObjectIdentifier contentTypt;
    private DEREncodable content;

    public TimeStampToken()
    {
        id_ct_TSTInfo = new DERObjectIdentifier("1.2.840.113549.1.9.16.1.4");
        hashAlgOID = null;
        tstInfo = null;
        tsaCert = null;
        contentTypt = PKCSObjectIdentifiers.signedData;
        content = null;
    }

    public TimeStampToken(ASN1Sequence seq)
        throws Exception
    {
        id_ct_TSTInfo = new DERObjectIdentifier("1.2.840.113549.1.9.16.1.4");
        hashAlgOID = null;
        tstInfo = null;
        tsaCert = null;
        contentTypt = PKCSObjectIdentifiers.signedData;
        content = null;
        ContentInfo contentInfo = ContentInfo.getInstance(seq);
        JCrypto jCrypto = new JCrypto();
        jCrypto.initialize(0, null);
        Session session = jCrypto.openSession(0);
        SignedDataParser sdParser = new SignedDataParser(session);
        SignedData signedData = sdParser.getSignedDataFromContentInfo(contentInfo);
        content = signedData;
        ASN1Set certSet = signedData.getCertificates();
        X509CertificateStructure certStruc = X509CertificateStructure.getInstance(certSet.getObjectAt(0));
        X509Cert cert = new X509Cert(certStruc);
        boolean verify = sdParser.verifySignedData(signedData, cert);
        if(!verify)
            throw new Exception("signature is not verified");
        ContentInfo tstContentInfo = signedData.getContentInfo();
        DERObjectIdentifier id_tstInfo = tstContentInfo.getContentType();
        if(!id_tstInfo.equals(id_ct_TSTInfo))
        {
            throw new Exception("wrong type of TSTInfo");
        } else
        {
            ASN1OctetString octetString = ASN1OctetString.getInstance(tstContentInfo.getContent());
            ASN1Sequence seqTSTInfo = Parser.oct2Seq(octetString);
            tstInfo = new TSTInfo(seqTSTInfo);
            return;
        }
    }

    public void setHashAlgOID(DERObjectIdentifier hashAlgOID)
    {
        this.hashAlgOID = hashAlgOID;
    }

    public void setTSTInfo(TSTInfo tstInfo)
    {
        this.tstInfo = tstInfo;
    }

    public TSTInfo getTSTInfo()
    {
        return tstInfo;
    }

    public void setTSACert(X509Cert tsaCert)
    {
        this.tsaCert = tsaCert;
    }

    public ContentInfo generateTimeStampToken(Session session, JKey priKey)
        throws Exception
    {
        if(tsaCert == null)
            throw new Exception("tsaCert must not be null,call setTSACert() to set TSA's certificate");
        if(hashAlgOID == null)
            throw new Exception("hash algorithm OID must not be null,call setHashAlgOID() to set it");
        if(tstInfo == null)
        {
            throw new Exception("TSTInfo must not be null,call setTSTInfo() to set it");
        } else
        {
            SignedDataParser sdParser = new SignedDataParser(session);
            DERSet x509Certs = new DERSet(tsaCert.getCertStructure());
            byte bTstInfo[] = Parser.writeDERObj2Bytes(tstInfo.getDERObject());
            SignedData sd = sdParser.generateSignedData(true, id_ct_TSTInfo, bTstInfo, hashAlgOID, priKey, x509Certs, null);
            content = sd;
            return sdParser.generateSignedDataContent(sd);
        }
    }

    public ContentInfo getDERObject()
    {
        ContentInfo contentInfo = new ContentInfo(contentTypt, content);
        return contentInfo;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -