Timestamping messages
With the toolkit classes, your application can request timestamps to a timestamping service.
Logging the user
Instantiate a user, set the connection to the Directory (if the user provides the IP address), and log in.
FileInputStream credentials = new FileInputStream (<credentials_location>);SecureStringBuffer password = new SecureStringBuffer(new StringBuffer(<user_password>));User user = new User();if (<IP address> != null){ JNDIDirectory dir = new JNDIDirectory (<ip>, <port>); user.setConnections(dir, null);}CredentialReader credReader = new StreamProfileReader(credentials);user.login(credReader, password>);Signing the message
Create an output stream to write the signed data to memory.
ByteArrayOutputStream encodedP7Data = new ByteArrayOutputStream();Create the signed PKCS #7 data using the SIGN_ONLY operation.
PKCS7EncodeStream p7EncodeStream = new PKCS7EncodeStream(user, encodedP7Data, PKCS7EncodeStream.SIGN_ONLY);Configuring the timestamp request
Create the timestamp validation mechanism and retrieve a certificate verifier using the getCertVerifier method.
TimeStampVerifier timeStampVerifier = new TimeStampVerifier((CertVerifier)user.getCertVerifier);Create the HTTP connection to the timestamping service.
TimeStampTransport transport = new HttpTimeStampTransport("http://www.mycompany.com:1234/tsa");Instantiate a timestamp client.
TimeStampClient timeStampClient = new TimeStampClient(transport, timeStampVerifier);Optionally, specify the hash algorithm for the timestamp request.
timeStampClient.setHashAlgorithm(AlgorithmID.MessageDigestAlgs.md5;If your application does not specify the algorithm, the default algorithm, SHA1, will be used.
Optionally, request the timestamping service to return the timestamp certificate.
timeStampClient.setRequestTSACert(Boolean.TRUE);Requesting the timestamp
Request a timestamp for the signature.
p7EncodeStream.requestTimeStamp(timeStampClient);Writing the timestamped message
Write the signed and timestamped data to the encode stream.
p7EncodeStream.write(TEST_DATA);p7EncodeStream.flush();p7EncodeStream.close();