// creating TimeStampToken
String policy = "1.2.3.4.5";
String sha1 = "1.3.14.3.2.26";
MessageImprint msgImprint = new MessageImprint(new AlgorithmIdentifier(
sha1), new byte[20]);
Date genTime = new Date();
BigInteger nonce = BigInteger.valueOf(1234567890L);
// accuracy is 1 second
int[] accuracy = new int[] { 1, 0, 0 };
GeneralName tsa = new GeneralName(new Name("CN=AnAuthority"));
Extensions exts = new Extensions();
// Time-Stamping extension OID: as defined in RFC 3161
int[] timeStampingExtOID = new int[] { 1, 3, 6, 1, 5, 5, 7, 3, 8 };
byte[] timeStampingExtValue = new byte[] { (byte) 1, (byte) 2, (byte) 3 };
Extension ext = new Extension(timeStampingExtOID, true,
timeStampingExtValue);
exts.addExtension(ext);
TSTInfo tSTInfo = new TSTInfo(1, policy, msgImprint, BigInteger.TEN,
genTime, accuracy, Boolean.FALSE, nonce, tsa, exts);
Object[] issuerAndSerialNumber = new Object[] { new Name("CN=issuer"),
ASN1Integer.fromIntValue(12345) };
// SHA1withDSA OID
String sha1dsa = "1.2.840.10040.4.3";
SignerInfo sigInfo = new SignerInfo(1, issuerAndSerialNumber,
new AlgorithmIdentifier(sha1), null, new AlgorithmIdentifier(
sha1dsa), new byte[20], null);
// TSTInfo OID according to RFC 3161
int[] tSTInfoOid = new int[] { 1, 2, 840, 113549, 1, 9, 16, 1, 4 };
ContentInfo tSTInfoEncoded = new ContentInfo(tSTInfoOid,
ASN1OctetString.getInstance().encode(
TSTInfo.ASN1.encode(tSTInfo)));
SignedData tokenContent = new SignedData(1, Collections
.singletonList(new AlgorithmIdentifier(sha1)), tSTInfoEncoded,
null, null, Collections.singletonList(sigInfo));
ContentInfo timeStampToken = new ContentInfo(ContentInfo.SIGNED_DATA,
tokenContent);
TimeStampResp response = new TimeStampResp(status, timeStampToken);