Package org.bouncycastle.tsp

Examples of org.bouncycastle.tsp.TimeStampRequestGenerator


        // 32-bit cryptographic nonce
        SecureRandom random = new SecureRandom();
        int nonce = random.nextInt();

        // generate TSA request
        TimeStampRequestGenerator tsaGenerator = new TimeStampRequestGenerator();
        tsaGenerator.setCertReq(true);
        ASN1ObjectIdentifier oid = getHashObjectIdentifier(digest.getAlgorithm());
        TimeStampRequest request = tsaGenerator.generate(oid, hash, BigInteger.valueOf(nonce));

        // get TSA response
        byte[] tsaResponse = getTSAResponse(request.getEncoded());

        TimeStampResponse response;
View Full Code Here


     * @throws TSPException
     */
    public byte[] getTimeStampToken(byte[] imprint) throws IOException, TSPException {
        byte[] respBytes = null;
            // Setup the time stamp request
            TimeStampRequestGenerator tsqGenerator = new TimeStampRequestGenerator();
            tsqGenerator.setCertReq(true);
            // tsqGenerator.setReqPolicy("1.3.6.1.4.1.601.10.3.1");
            BigInteger nonce = BigInteger.valueOf(System.currentTimeMillis());
            TimeStampRequest request = tsqGenerator.generate(new ASN1ObjectIdentifier(DigestAlgorithms.getAllowedDigests(digestAlgorithm)), imprint, nonce);
            byte[] requestBytes = request.getEncoded();
           
            // Call the communications layer
            respBytes = getTSAResponse(requestBytes);
           
View Full Code Here

  }
  public void run() {
   
    try {
      boolean base64 = true;
      TimeStampRequestGenerator timeStampRequestGenerator = new TimeStampRequestGenerator();

      Random rand = new Random();
      int nonce = rand.nextInt();
      byte[] digestBytes = new byte[20];
      if (infile != null) {
        digestBytes = FileTools.readFiletoBuffer(infile);
      }
      MessageDigest dig = MessageDigest.getInstance(TSPAlgorithms.SHA1, "BC");
      dig.update(digestBytes);
      byte[] digest = dig.digest();
      TimeStampRequest timeStampRequest = timeStampRequestGenerator.generate(TSPAlgorithms.SHA1, digest, BigInteger.valueOf(nonce));

      // create a singular HttpClient object
      HttpClient client = new HttpClient();

      //establish a connection within 5 seconds
View Full Code Here

     * @throws TSPException
     */
    public byte[] getTimeStampToken(byte[] imprint) throws IOException, TSPException {
        byte[] respBytes = null;
            // Setup the time stamp request
            TimeStampRequestGenerator tsqGenerator = new TimeStampRequestGenerator();
            tsqGenerator.setCertReq(true);
            // tsqGenerator.setReqPolicy("1.3.6.1.4.1.601.10.3.1");
            BigInteger nonce = BigInteger.valueOf(System.currentTimeMillis());
            TimeStampRequest request = tsqGenerator.generate(new ASN1ObjectIdentifier(DigestAlgorithms.getAllowedDigests(digestAlgorithm)), imprint, nonce);
            byte[] requestBytes = request.getEncoded();
           
            // Call the communications layer
            respBytes = getTSAResponse(requestBytes);
           
View Full Code Here

  protected TimeStampRequest getTimeStampRequest(final byte[] imprint) {
    Digester digester = new BasicDigester(DigestType.valueOf(DigestType.SHA1.getAlgorithm()));
    byte[] digest = digester.digest(imprint);

    TimeStampRequestGenerator generator = new TimeStampRequestGenerator();
    generator.setCertReq(true);

    BigInteger nonce = BigInteger.valueOf(System.currentTimeMillis());
    TimeStampRequest request = generator.generate(BouncyCastleTimeStampClient.RSA_OID, digest, nonce);

    return request;
  }
View Full Code Here

  public void testServletRequestInBinaryModeWorks() throws IOException, TSPException {
    CloseableHttpClient client = builder.build();
    HttpHost host = new HttpHost(hostname, port);
    HttpPost post = new HttpPost("/tsa");
   
    TimeStampRequestGenerator generator = new TimeStampRequestGenerator();
    TimeStampRequest timeStampRequest = generator.generate(TSPAlgorithms.SHA1, DigestHelper.digest("this is a test message"));
   
    ByteArrayEntity entity = new ByteArrayEntity(timeStampRequest.getEncoded());
   
    post.setHeader("Content-Type", TimestampServlet.TIMESTAMP_QUERY_CONTENT_TYPE);
    post.setHeader(TimestampServlet.TRANSFER_ENCODING_HEADER, TimestampServlet.TRANSFER_ENCODING_BINARY);
View Full Code Here

   
    CloseableHttpClient client = builder.build();
    HttpHost host = new HttpHost(hostname, port);
    HttpPost post = new HttpPost("/tsa");
   
    TimeStampRequestGenerator generator = new TimeStampRequestGenerator();
    TimeStampRequest timeStampRequest = generator.generate(TSPAlgorithms.SHA1, DigestHelper.digest("this is a test message"));
   
    ByteArrayEntity entity = new ByteArrayEntity(Base64.encode(timeStampRequest.getEncoded()));
   
    post.setHeader("Content-Type", TimestampServlet.TIMESTAMP_QUERY_CONTENT_TYPE);
    post.setHeader(TimestampServlet.TRANSFER_ENCODING_HEADER, TimestampServlet.TRANSFER_ENCODING_BASE64);
View Full Code Here

  public void binaryStressTest() throws IOException, TSPException {
    CloseableHttpClient client = builder.build();
    HttpHost host = new HttpHost(hostname, port);
   
    for (int i = 0; i < maxStress; i++) {
      TimeStampRequestGenerator generator = new TimeStampRequestGenerator();
      TimeStampRequest timeStampRequest = generator.generate(TSPAlgorithms.SHA1, DigestHelper.digest("this is a test message " + i));
     
      ByteArrayEntity entity = new ByteArrayEntity(timeStampRequest.getEncoded());
     
      HttpPost post = new HttpPost("/tsa");
      post.setHeader("Content-Type", TimestampServlet.TIMESTAMP_QUERY_CONTENT_TYPE);
View Full Code Here

    HttpHost host = new HttpHost(hostname, port);
   
    for (int i = 0; i < maxStress; i++) {
      HttpPost post = new HttpPost("/tsa");
     
      TimeStampRequestGenerator generator = new TimeStampRequestGenerator();
      TimeStampRequest timeStampRequest = generator.generate(TSPAlgorithms.SHA1, DigestHelper.digest("this is a test message " + i));
     
      ByteArrayEntity entity = new ByteArrayEntity(Base64.encode(timeStampRequest.getEncoded()));
     
      post.setHeader("Content-Type", TimestampServlet.TIMESTAMP_QUERY_CONTENT_TYPE);
      post.setHeader(TimestampServlet.TRANSFER_ENCODING_HEADER, TimestampServlet.TRANSFER_ENCODING_BASE64);
View Full Code Here

   
    CloseableHttpClient client = builder.build();
    HttpHost host = new HttpHost(hostname, port);
    HttpPost post = new HttpPost("/tsa");
   
    TimeStampRequestGenerator generator = new TimeStampRequestGenerator();
    TimeStampRequest timeStampRequest = generator.generate(TSPAlgorithms.SHA1, DigestHelper.digest("this is a test message"));
    TimeStampRequest otherTimeStampRequest = generator.generate(TSPAlgorithms.SHA1, DigestHelper.digest("this is another test message"));
   
    ByteArrayEntity entity = new ByteArrayEntity(Base64.encode(timeStampRequest.getEncoded()));
   
    post.setHeader("Content-Type", TimestampServlet.TIMESTAMP_QUERY_CONTENT_TYPE);
    post.setHeader(TimestampServlet.TRANSFER_ENCODING_HEADER, TimestampServlet.TRANSFER_ENCODING_BASE64);
View Full Code Here

TOP

Related Classes of org.bouncycastle.tsp.TimeStampRequestGenerator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.