Represents the TSTInfo strcture within a time-stamp token (RFC 3161). : Time « Development Class « Java

Represents the TSTInfo strcture within a time-stamp token (RFC 3161).

 * XAdES4j - A Java library for generation and verification of XAdES signatures.
 * Copyright (C) 2010 Luis Goncalves.
 * XAdES4j is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 3 of the License, or any later version.
 * XAdES4j is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * You should have received a copy of the GNU Lesser General Public License along
 * with XAdES4j. If not, see <>.
//package xades4j.utils;

import java.math.BigInteger;
import java.util.Date;


 * Represents the TSTInfo strcture within a time-stamp token (RFC 3161). Based
 * on the class. Copyright 2006 Sun
 * Microsystems, Inc. All rights reserved. author: Vincent Ryan
 * <p>
 * Added getters for fields other than genTime.
 * @author Lus
public class TimeStampTokenInfo {
  private int version;
  private ObjectIdentifier policy;
  private BigInteger serialNumber;
  private AlgorithmId hashAlgorithm;
  private byte[] hashedMessage;
  private Date genTime;

   * Constructs an object to store a timestamp token.
   * @param timestampTokenInfo
   *            a buffer containing the ASN.1 BER encoding of the TSTInfo
   *            element defined in RFC 3161.
  public TimeStampTokenInfo(byte[] timestampTokenInfo) throws IOException {
    if (timestampTokenInfo == null)
      throw new IOException("No timestamp token info");

   * Extract the date and time from the timestamp token.
   * @return The date and time when the timestamp was generated.
  public Date getDate() {
    return genTime;

  public AlgorithmId getHashAlgorithm() {
    return hashAlgorithm;

  public byte[] getHashedMessage() {
    return hashedMessage;

  public ObjectIdentifier getPolicy() {
    return policy;

  public BigInteger getSerialNumber() {
    return serialNumber;

  public int getVersion() {
    return version;

   * Parses the timestamp token info.
   * @param timestampTokenInfo A buffer containing an ASN.1 BER encoded
   * TSTInfo.
   * @throws IOException The exception is thrown if a problem is encountered
   * while parsing.
  private void parse(byte[] timestampTokenInfo) throws IOException {

    DerValue tstInfo = new DerValue(timestampTokenInfo);
    if (tstInfo.tag != DerValue.tag_Sequence)
      throw new IOException("Bad encoding for timestamp token info");
    // Parse version
    version =;

    // Parse policy
    policy =;

    // Parse messageImprint
    DerValue messageImprint =;
    hashAlgorithm = AlgorithmId.parse(;
    hashedMessage =;

    // Parse serialNumber
    serialNumber =;

    // Parse genTime
    genTime =;

    // Parse optional elements, if present
    if ( > 0) {
      // Parse accuracy
      // Parse ordering
      // Parse nonce
      // Parse tsa
      // Parse extensions


Related examples in the same category

1.Get Time From Date
2.ISO8601 Date Time Format
3.Time Format
4.Time Formatter
5.Returns time string
6.Returns the given date with the time values cleared
7.Convert the time to the midnight of the currently set date
8.Compare both times and dates
9.Tells you if the date part of a datetime is in a certain time range
10.Returns the given date with time set to the end of the day
11.Convert milliseconds to readable string
12.Determines whether or not a date has any time values (hour, minute, seconds or millisecondsReturns the given date with the time values cleared
13.Returns a formatted String from time
14.Time library
15.Elapsed time in hours/minutes/seconds
16.Sets the time on the same day to 00:00:00.000
17.Determines if given times span at least an entire day
18.Converts a given time in milliseconds into a XMLGregorianCalendar object.
19.Time Distance
20.Time Formatter
21.Format time
22.A utility class for representing a span of time.
23.GmtCalendar is a useful class for working with times that are based using GMT time.
24.Time Period
25.SimpleTimer enables bounded and unbounded waits.
26.Takes a time in milliseconds and returns an hours, minutes and seconds representation.
27.Format time in milliseconds