• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TimeStampRequestGenerator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.bouncycastle.tsp.TimeStampRequestGenerator的典型用法代码示例。如果您正苦于以下问题:Java TimeStampRequestGenerator类的具体用法?Java TimeStampRequestGenerator怎么用?Java TimeStampRequestGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TimeStampRequestGenerator类属于org.bouncycastle.tsp包,在下文中一共展示了TimeStampRequestGenerator类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createTimeStampToken

import org.bouncycastle.tsp.TimeStampRequestGenerator; //导入依赖的package包/类
public static TimeStampToken createTimeStampToken(PrivateKey privateKey, List<X509Certificate> certificateChain)
		throws Exception {

	Store certs = new JcaCertStore(certificateChain);

	TimeStampRequestGenerator requestGen = new TimeStampRequestGenerator();
	requestGen.setCertReq(true);
	TimeStampRequest request = requestGen.generate(TSPAlgorithms.SHA1, new byte[20], BigInteger.valueOf(100));

	TimeStampTokenGenerator tsTokenGen = new TimeStampTokenGenerator(
			new JcaSimpleSignerInfoGeneratorBuilder().build("SHA1withRSA", privateKey, certificateChain.get(0)),
			new JcaDigestCalculatorProviderBuilder().build()
					.get(new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1)),
			new ASN1ObjectIdentifier("1.2"));

	tsTokenGen.addCertificates(certs);
	return tsTokenGen.generate(request, BigInteger.ONE, new Date());
}
 
开发者ID:e-Contract,项目名称:jtrust,代码行数:19,代码来源:PKITestUtils.java


示例2: createRequest

import org.bouncycastle.tsp.TimeStampRequestGenerator; //导入依赖的package包/类
/**
 *
 * @param original
 * @param keystore
 * @param alias
 * @param digestAlgorithm
 * @return
 * @throws TimestampException
 * @throws IOException
 */
public byte[] createRequest(byte[] original, KeyStore keystore, String alias, DigestAlgorithmEnum digestAlgorithm) throws TimestampException, IOException {
    logger.log(Level.INFO, "Gerando o digest do conteudo");
    Digest digest = DigestFactory.getInstance().factoryDefault();
    digest.setAlgorithm(digestAlgorithm);
    byte[] hashedMessage = digest.digest(original);
    logger.log(Level.INFO, Base64.toBase64String(hashedMessage));

    logger.log(Level.INFO, "Montando a requisicao para o carimbador de tempo");
    TimeStampRequestGenerator timeStampRequestGenerator = new TimeStampRequestGenerator();
    timeStampRequestGenerator.setReqPolicy(new ASN1ObjectIdentifier("2.16.76.1.6.2"));
    timeStampRequestGenerator.setCertReq(true);
    timeStampRequest = timeStampRequestGenerator.generate(TSPAlgorithms.SHA256, hashedMessage, BigInteger.valueOf(100));
    byte request[] = timeStampRequest.getEncoded();

    logger.info("Efetuando a  assinatura do conteudo");
    RequestSigner requestSigner = new RequestSigner();
    byte[] signedRequest = requestSigner.assinar(keystore, alias, null, request);

    return signedRequest;
}
 
开发者ID:humbertopacheco,项目名称:timestamp,代码行数:31,代码来源:TimestampGenerator.java


示例3: createRequest

import org.bouncycastle.tsp.TimeStampRequestGenerator; //导入依赖的package包/类
/**
 * Cria uma requisição de carimbo de tempo assinada pelo usuario
 *
 * @param original O conteudo em bytes do arquivo a ser carimbado
 * @param privateKey
 * @param certificates
 * @param digestAlgorithm O algoritmo a ser utilizado para gerar o hash do
 * documento
 * @return Uma requisicao de carimbo de tempo
 * @throws TimestampException
 * @throws IOException
 */
public byte[] createRequest(byte[] original, PrivateKey privateKey, Certificate[] certificates, DigestAlgorithmEnum digestAlgorithm) throws TimestampException, IOException {
    logger.info("Gerando o digest do conteudo");
    Digest digest = DigestFactory.getInstance().factoryDefault();
    digest.setAlgorithm(digestAlgorithm);
    byte[] hashedMessage = digest.digest(original);
    logger.info(Base64.toBase64String(hashedMessage));

    logger.info("Montando a requisicao para o carimbador de tempo");
    TimeStampRequestGenerator timeStampRequestGenerator = new TimeStampRequestGenerator();
    timeStampRequestGenerator.setReqPolicy(new ASN1ObjectIdentifier("2.16.76.1.6.2"));
    timeStampRequestGenerator.setCertReq(true);
    timeStampRequest = timeStampRequestGenerator.generate(TSPAlgorithms.SHA256, hashedMessage, BigInteger.valueOf(100));
    byte request[] = timeStampRequest.getEncoded();

    logger.info("Efetuando a  assinatura do conteudo");
    RequestSigner requestSigner = new RequestSigner();
    byte[] signedRequest = requestSigner.signRequest(privateKey, certificates, request);
    return signedRequest;
}
 
开发者ID:humbertopacheco,项目名称:timestamp,代码行数:32,代码来源:TimestampGenerator.java


示例4: createRequest

import org.bouncycastle.tsp.TimeStampRequestGenerator; //导入依赖的package包/类
/**
 * Creates a time stamp request, signed with the users's certificate.
 *
 * @param privateKey private key to sign with
 * @param certificates certificate chain
 * @param content  set null if signing only hash
 * @param hash  set null if signing content
 * @return A time stamp request
 * @throws CertificateCoreException exception
 */
public byte[] createRequest(PrivateKey privateKey, Certificate[] certificates, byte[] content, byte[] hash) throws CertificateCoreException {
    try {
        logger.info(timeStampMessagesBundle.getString("info.timestamp.digest"));
        Digest digest = DigestFactory.getInstance().factoryDefault();
        digest.setAlgorithm(DigestAlgorithmEnum.SHA_256);
        byte[] hashedMessage = null;
        if (content != null){
        	hashedMessage = digest.digest(content);                
            //logger.info(Base64.toBase64String(hashedMessage));	
        }else{
        	hashedMessage = hash;
        }
        
        logger.info(timeStampMessagesBundle.getString("info.timestamp.prepare.request"));
        TimeStampRequestGenerator timeStampRequestGenerator = new TimeStampRequestGenerator();
                    
        timeStampRequestGenerator.setReqPolicy(new ASN1ObjectIdentifier(TimeStampConfig.getInstance().getTSPOid()));
        timeStampRequestGenerator.setCertReq(true);
        BigInteger nonce = BigInteger.valueOf(100);
        timeStampRequest = timeStampRequestGenerator.generate(new ASN1ObjectIdentifier(TSPAlgorithms.SHA256.getId()), hashedMessage, nonce);
        byte request[] = timeStampRequest.getEncoded();
        logger.info(timeStampMessagesBundle.getString("info.timestamp.sign.request"));
        RequestSigner requestSigner = new RequestSigner();
        byte[] signedRequest = requestSigner.signRequest(privateKey, certificates, request, "SHA256withRSA");
        return signedRequest;
    } catch (IOException ex) { 
    
        throw new CertificateCoreException(ex.getMessage());
    }
}
 
开发者ID:demoiselle,项目名称:signer,代码行数:41,代码来源:TimeStampOperator.java


示例5: testTimestampServerTrust

import org.bouncycastle.tsp.TimeStampRequestGenerator; //导入依赖的package包/类
private void testTimestampServerTrust(String tsaLocation) throws Exception {
	// setup
	TimeStampRequestGenerator requestGen = new TimeStampRequestGenerator();
	requestGen.setCertReq(true);
	TimeStampRequest request = requestGen.generate(TSPAlgorithms.SHA1,
			new byte[20], BigInteger.valueOf(100));
	byte[] requestData = request.getEncoded();

	DefaultHttpClient httpClient = new DefaultHttpClient();
	// HttpHost proxy = new HttpHost("proxy.yourict.net", 8080);
	// httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
	// proxy);
	HttpPost postMethod = new HttpPost(tsaLocation);
	ContentType contentType = ContentType
			.create("application/timestamp-query");
	HttpEntity requestEntity = new ByteArrayEntity(requestData, contentType);
	postMethod.addHeader("User-Agent", "jTrust TSP Client");
	postMethod.setEntity(requestEntity);

	// operate
	long t0 = System.currentTimeMillis();
	HttpResponse httpResponse = httpClient.execute(postMethod);
	StatusLine statusLine = httpResponse.getStatusLine();
	int statusCode = statusLine.getStatusCode();
	long t1 = System.currentTimeMillis();
	LOG.debug("dt TSP: " + (t1 - t0) + " ms");
	if (statusCode != HttpURLConnection.HTTP_OK) {
		LOG.error("Error contacting TSP server " + TSA_LOCATION);
		throw new Exception("Error contacting TSP server " + TSA_LOCATION);
	}

	HttpEntity httpEntity = httpResponse.getEntity();
	TimeStampResponse tspResponse = new TimeStampResponse(
			httpEntity.getContent());
	postMethod.releaseConnection();

	TimeStampToken timeStampToken = tspResponse.getTimeStampToken();
	SignerId signerId = timeStampToken.getSID();
	Store certificatesStore = timeStampToken.getCertificates();
	Collection<X509CertificateHolder> signerCollection = certificatesStore
			.getMatches(signerId);

	Iterator<X509CertificateHolder> signerCollectionIterator = signerCollection
			.iterator();
	X509CertificateHolder signerCertificateHolder = signerCollectionIterator
			.next();

	// TODO: check time-stamp token signature

	List<X509Certificate> certificateChain = getCertificateChain(
			signerCertificateHolder, certificatesStore);

	for (X509Certificate cert : certificateChain) {
		LOG.debug("certificate subject: " + cert.getSubjectX500Principal());
		LOG.debug("certificate issuer: " + cert.getIssuerX500Principal());
	}

	CertificateRepository certificateRepository = BelgianTrustValidatorFactory
			.createTSACertificateRepository();
	TrustValidator trustValidator = new TrustValidator(
			certificateRepository);
	// NetworkConfig networkConfig = new NetworkConfig("proxy.yourict.net",
	// 8080);
	TrustValidatorDecorator trustValidatorDecorator = new TrustValidatorDecorator(
			null);
	trustValidatorDecorator.addDefaultTrustLinkerConfig(trustValidator);

	trustValidator.isTrusted(certificateChain);
}
 
开发者ID:e-Contract,项目名称:jtrust,代码行数:70,代码来源:TSATest.java



注:本文中的org.bouncycastle.tsp.TimeStampRequestGenerator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java StringNode类代码示例发布时间:2022-05-22
下一篇:
Java SSTableUtils类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap