use of org.bouncycastle.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;
}
use of org.bouncycastle.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;
}
use of org.bouncycastle.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));
}
}
use of org.bouncycastle.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));
}
}
use of org.bouncycastle.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;
}
Aggregations