Search in sources :

Example 1 with TimeStampReq

use of com.github.zhenwei.pkix.util.asn1.tsp.TimeStampReq in project gdmatrix by gdmatrix.

the class P7MUtils method createTimeStamp.

public static ContentInfo createTimeStamp(String serviceURI, byte[] message) throws Exception {
    String nonce = String.valueOf((int) (Math.random() * 1000000));
    // es crea la peticio a la TSA
    TimeStampReq timeStampRequest = createTimeStampRequest(// message
    message, // nonce
    nonce, // requireCert
    true, // extensions
    null, // digestAlgorithm identifier
    "1.3.14.3.2.26", // timestampPolicy
    "0.4.0.2023.1.1");
    // s'envia la peticio creada
    TimeStampResp timeStampResponse = sendTimestampRequest(timeStampRequest, serviceURI);
    ContentInfo contentInfo = timeStampResponse.getTimeStampToken();
    return contentInfo;
}
Also used : TimeStampReq(org.bouncycastle.asn1.tsp.TimeStampReq) ContentInfo(org.bouncycastle.asn1.cms.ContentInfo) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) DEROctetString(org.bouncycastle.asn1.DEROctetString) TimeStampResp(org.bouncycastle.asn1.tsp.TimeStampResp)

Example 2 with TimeStampReq

use of com.github.zhenwei.pkix.util.asn1.tsp.TimeStampReq in project gdmatrix by gdmatrix.

the class CMSUtils method createTimeStampRequest.

public static TimeStampReq createTimeStampRequest(byte[] message, String nonce, boolean requireCert, Extensions extensions, String digestAlgorithm, String timestampPolicy) throws NoSuchAlgorithmException {
    MessageDigest md = MessageDigest.getInstance("SHA1");
    byte[] hashedMsg = md.digest(message);
    ASN1ObjectIdentifier identifier = new ASN1ObjectIdentifier(digestAlgorithm);
    org.bouncycastle.asn1.tsp.MessageImprint imprint = new org.bouncycastle.asn1.tsp.MessageImprint(new AlgorithmIdentifier(identifier), hashedMsg);
    TimeStampReq request = new TimeStampReq(imprint, timestampPolicy != null ? new ASN1ObjectIdentifier(timestampPolicy) : null, nonce != null ? new ASN1Integer(nonce.getBytes()) : null, ASN1Boolean.getInstance(requireCert), extensions);
    return request;
}
Also used : TimeStampReq(org.bouncycastle.asn1.tsp.TimeStampReq) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) MessageDigest(java.security.MessageDigest) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Example 3 with TimeStampReq

use of com.github.zhenwei.pkix.util.asn1.tsp.TimeStampReq in project LinLong-Java by zhenwei1108.

the class TimeStampRequestGenerator method generate.

/**
 * @deprecated use method taking ANS1ObjectIdentifier
 */
public TimeStampRequest generate(String digestAlgorithmOID, byte[] digest, BigInteger nonce) {
    if (digestAlgorithmOID == null) {
        throw new IllegalArgumentException("No digest algorithm specified");
    }
    ASN1ObjectIdentifier digestAlgOID = new ASN1ObjectIdentifier(digestAlgorithmOID);
    AlgorithmIdentifier algID = dgstAlgFinder.find(digestAlgOID);
    MessageImprint messageImprint = new MessageImprint(algID, digest);
    Extensions ext = null;
    if (!extGenerator.isEmpty()) {
        ext = extGenerator.generate();
    }
    if (nonce != null) {
        return new TimeStampRequest(new TimeStampReq(messageImprint, reqPolicy, new ASN1Integer(nonce), certReq, ext));
    } else {
        return new TimeStampRequest(new TimeStampReq(messageImprint, reqPolicy, null, certReq, ext));
    }
}
Also used : TimeStampReq(com.github.zhenwei.pkix.util.asn1.tsp.TimeStampReq) MessageImprint(com.github.zhenwei.pkix.util.asn1.tsp.MessageImprint) ASN1Integer(com.github.zhenwei.core.asn1.ASN1Integer) Extensions(com.github.zhenwei.core.asn1.x509.Extensions) ASN1ObjectIdentifier(com.github.zhenwei.core.asn1.ASN1ObjectIdentifier) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)

Example 4 with TimeStampReq

use of com.github.zhenwei.pkix.util.asn1.tsp.TimeStampReq in project LinLong-Java by zhenwei1108.

the class TimeStampRequestGenerator method generate.

public TimeStampRequest generate(AlgorithmIdentifier digestAlgorithmID, byte[] digest, BigInteger nonce) {
    if (digestAlgorithmID == null) {
        throw new IllegalArgumentException("digest algorithm not specified");
    }
    MessageImprint messageImprint = new MessageImprint(digestAlgorithmID, digest);
    Extensions ext = null;
    if (!extGenerator.isEmpty()) {
        ext = extGenerator.generate();
    }
    if (nonce != null) {
        return new TimeStampRequest(new TimeStampReq(messageImprint, reqPolicy, new ASN1Integer(nonce), certReq, ext));
    } else {
        return new TimeStampRequest(new TimeStampReq(messageImprint, reqPolicy, null, certReq, ext));
    }
}
Also used : TimeStampReq(com.github.zhenwei.pkix.util.asn1.tsp.TimeStampReq) MessageImprint(com.github.zhenwei.pkix.util.asn1.tsp.MessageImprint) ASN1Integer(com.github.zhenwei.core.asn1.ASN1Integer) Extensions(com.github.zhenwei.core.asn1.x509.Extensions)

Example 5 with TimeStampReq

use of com.github.zhenwei.pkix.util.asn1.tsp.TimeStampReq in project gdmatrix by gdmatrix.

the class P7MUtils method createTimeStampRequest.

public static TimeStampReq createTimeStampRequest(byte[] message, String nonce, boolean requireCert, Extensions extensions, String digestAlgorithm, String timestampPolicy) throws NoSuchAlgorithmException {
    MessageDigest md = MessageDigest.getInstance("SHA1");
    byte[] hashedMsg = md.digest(message);
    ASN1ObjectIdentifier identifier = new ASN1ObjectIdentifier(digestAlgorithm);
    org.bouncycastle.asn1.tsp.MessageImprint imprint = new org.bouncycastle.asn1.tsp.MessageImprint(new AlgorithmIdentifier(identifier), hashedMsg);
    TimeStampReq request = new TimeStampReq(imprint, timestampPolicy != null ? new ASN1ObjectIdentifier(timestampPolicy) : null, nonce != null ? new ASN1Integer(nonce.getBytes()) : null, ASN1Boolean.getInstance(requireCert), extensions);
    return request;
}
Also used : TimeStampReq(org.bouncycastle.asn1.tsp.TimeStampReq) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) MessageDigest(java.security.MessageDigest) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Aggregations

TimeStampReq (org.bouncycastle.asn1.tsp.TimeStampReq)4 ASN1Integer (com.github.zhenwei.core.asn1.ASN1Integer)2 Extensions (com.github.zhenwei.core.asn1.x509.Extensions)2 MessageImprint (com.github.zhenwei.pkix.util.asn1.tsp.MessageImprint)2 TimeStampReq (com.github.zhenwei.pkix.util.asn1.tsp.TimeStampReq)2 MessageDigest (java.security.MessageDigest)2 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)2 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)2 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)2 DEROctetString (org.bouncycastle.asn1.DEROctetString)2 ContentInfo (org.bouncycastle.asn1.cms.ContentInfo)2 TimeStampResp (org.bouncycastle.asn1.tsp.TimeStampResp)2 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)2 ASN1ObjectIdentifier (com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)1 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)1