当前位置: 首页>>代码示例>>Java>>正文


Java Pkcs12SignatureToken类代码示例

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


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

示例1: generate

import eu.europa.esig.dss.token.Pkcs12SignatureToken; //导入依赖的package包/类
@Test
public void generate() throws Exception {
	CertificateService service = new CertificateService();
	MockPrivateKeyEntry entry = service.generateCertificateChain(SignatureAlgorithm.RSA_SHA256);

	KeyStore keystore = createKeyStore();
	addCertificate(keystore, "certificate", entry.getCertificate(), entry);

	OutputStream fos = new FileOutputStream(KEYSTORE_FILEPATH);
	keystore.store(fos, KEYSTORE_PASSWORD.toCharArray());

	AbstractSignatureTokenConnection signingToken = new Pkcs12SignatureToken(KEYSTORE_PASSWORD, KEYSTORE_FILEPATH);
	Assert.assertEquals(1, signingToken.getKeys().size());
	DSSPrivateKeyEntry privateEntry = signingToken.getKeys().get(0);
	Assert.assertNotNull(privateEntry);
}
 
开发者ID:esig,项目名称:dss,代码行数:17,代码来源:PKCS12KeystoreWithKeyEntryGeneration.java

示例2: getToken

import eu.europa.esig.dss.token.Pkcs12SignatureToken; //导入依赖的package包/类
private SignatureTokenConnection getToken(SignatureModel model) throws IOException {
	switch (model.getTokenType()) {
	case PKCS11:
		return new Pkcs11SignatureToken(model.getPkcsFile().getAbsolutePath(), model.getPassword().toCharArray());
	case PKCS12:
		return new Pkcs12SignatureToken(model.getPkcsFile(), model.getPassword());
	case MSCAPI:
		return new MSCAPISignatureToken();
	default:
		throw new IllegalArgumentException("Unsupported token type " + model.getTokenType());
	}
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:13,代码来源:SigningTask.java

示例3: PKCS12SignatureToken

import eu.europa.esig.dss.token.Pkcs12SignatureToken; //导入依赖的package包/类
/**
 * Constructs PKCS12 signer object. If more than one key is provided only first is used
 *
 * @param fileName .p12 file name and path
 * @param password keystore password as char array
 */
//TODO new Constructor with password AS String
public PKCS12SignatureToken(String fileName, char[] password){
  logger.info("Using PKCS#12 signature token from file: " + fileName);
  try {
    signatureTokenConnection = new Pkcs12SignatureToken(fileName, String.valueOf(password));
  } catch (IOException e) {
    throw new DigiDoc4JException(e.getMessage());
  }
  keyEntry = signatureTokenConnection.getKeys().get(0);
}
 
开发者ID:open-eid,项目名称:digidoc4j,代码行数:17,代码来源:PKCS12SignatureToken.java

示例4: setUp

import eu.europa.esig.dss.token.Pkcs12SignatureToken; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
	this.documentationFilter = document("{method-name}", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()));
	this.spec = new RequestSpecBuilder().addFilter(documentationConfiguration(this.restDocumentation)).addFilter(this.documentationFilter).build();
	this.token = new Pkcs12SignatureToken(new FileInputStream("src/test/resources/user_a_rsa.p12"), "password");
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:7,代码来源:RestDocumentationApp.java

示例5: main

import eu.europa.esig.dss.token.Pkcs12SignatureToken; //导入依赖的package包/类
public static void main(String[] args) throws IOException {

		// GET document to be signed -
		// Return DSSDocument toSignDocument
		prepareXmlDoc();

		// Create token connection base on a self sign certificate
		String pkcs12TokenFile = getPathFromResource("/rca.p12");
		signingToken = new Pkcs12SignatureToken("password", pkcs12TokenFile);
		privateKey = signingToken.getKeys().get(0);

		// Preparing parameters for the XAdES signature
		XAdESSignatureParameters parameters = new XAdESSignatureParameters();
		// We choose the level of the signature (-B, -T, -LT, -LTA).
		parameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B);
		// We choose the type of the signature packaging (ENVELOPED, ENVELOPING, DETACHED).
		parameters.setSignaturePackaging(SignaturePackaging.ENVELOPED);
		// We set the digest algorithm to use with the signature algorithm. You must use the
		// same parameter when you invoke the method sign on the token. The default value is
		// SHA256
		parameters.setDigestAlgorithm(DigestAlgorithm.SHA256);

		// We set the signing certificate
		parameters.setSigningCertificate(privateKey.getCertificate());
		// We set the certificate chain
		parameters.setCertificateChain(privateKey.getCertificateChain());

		// Create common certificate verifier
		CommonCertificateVerifier commonCertificateVerifier = new CommonCertificateVerifier();
		// Create XAdES xadesService for signature
		XAdESService service = new XAdESService(commonCertificateVerifier);

		// Get the SignedInfo XML segment that need to be signed.
		ToBeSigned dataToSign = service.getDataToSign(toSignDocument, parameters);

		// This function obtains the signature value for signed information using the
		// private key and specified algorithm
		DigestAlgorithm digestAlgorithm = parameters.getDigestAlgorithm();
		SignatureValue signatureValue = signingToken.sign(dataToSign, digestAlgorithm, privateKey);

		// We invoke the xadesService to sign the document with the signature value obtained in
		// the previous step.
		DSSDocument signedDocument = service.signDocument(toSignDocument, parameters, signatureValue);

		signedDocument.save("target/signedXmlXadesB_WithSelfSignedCertificate.xml");
	}
 
开发者ID:esig,项目名称:dss,代码行数:47,代码来源:SignXmlXadesBWithSelfSignedCertificate.java

示例6: preparePKCS12TokenAndKey

import eu.europa.esig.dss.token.Pkcs12SignatureToken; //导入依赖的package包/类
/**
 * This method sets the common parameters.
 * 
 * @throws IOException
 */
protected static void preparePKCS12TokenAndKey() throws IOException {
	String pkcs12TokenFile = getPathFromResource("/user_a_rsa.p12");
	signingToken = new Pkcs12SignatureToken(pkcs12TokenFile, "password");
	privateKey = signingToken.getKeys().get(0);
}
 
开发者ID:esig,项目名称:dss,代码行数:11,代码来源:Cookbook.java

示例7: main

import eu.europa.esig.dss.token.Pkcs12SignatureToken; //导入依赖的package包/类
public static void main(String[] args) throws IOException {

		// tag::demo[]

		SignatureTokenConnection token = new Pkcs12SignatureToken("src/main/resources/user_a_rsa.p12", "password");

		List<DSSPrivateKeyEntry> keys = token.getKeys();
		for (DSSPrivateKeyEntry entry : keys) {
			System.out.println(entry.getCertificate().getCertificate());
		}

		ToBeSigned toBeSigned = new ToBeSigned("Hello world".getBytes());
		SignatureValue signatureValue = token.sign(toBeSigned, DigestAlgorithm.SHA256, keys.get(0));

		System.out.println("Signature value : " + Utils.toBase64(signatureValue.getValue()));

		// end::demo[]

	}
 
开发者ID:esig,项目名称:dss,代码行数:20,代码来源:PKCS12Snippet.java

示例8: getOCSPAccessCertificatePrivateKey

import eu.europa.esig.dss.token.Pkcs12SignatureToken; //导入依赖的package包/类
private DSSPrivateKeyEntry getOCSPAccessCertificatePrivateKey() throws IOException {
  Pkcs12SignatureToken signatureTokenConnection = new Pkcs12SignatureToken(configuration.getOCSPAccessCertificateFileName(), configuration.getOCSPAccessCertificatePasswordAsString());
  return signatureTokenConnection.getKeys().get(0);
}
 
开发者ID:open-eid,项目名称:digidoc4j,代码行数:5,代码来源:SKOnlineOCSPSource.java

示例9: preparePKCS12TokenAndKey

import eu.europa.esig.dss.token.Pkcs12SignatureToken; //导入依赖的package包/类
/**
 * This method sets the common parameters.
 * 
 * @throws IOException
 */
protected static void preparePKCS12TokenAndKey() throws IOException {
	signingToken = new Pkcs12SignatureToken("src/main/resources/user_a_rsa.p12", "password");
	privateKey = signingToken.getKeys().get(0);
}
 
开发者ID:esig,项目名称:dss,代码行数:10,代码来源:CookbookTools.java


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