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


Java PAdESSignatureParameters.setSignaturePackaging方法代码示例

本文整理汇总了Java中eu.europa.esig.dss.pades.PAdESSignatureParameters.setSignaturePackaging方法的典型用法代码示例。如果您正苦于以下问题:Java PAdESSignatureParameters.setSignaturePackaging方法的具体用法?Java PAdESSignatureParameters.setSignaturePackaging怎么用?Java PAdESSignatureParameters.setSignaturePackaging使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eu.europa.esig.dss.pades.PAdESSignatureParameters的用法示例。


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

示例1: getParameters

import eu.europa.esig.dss.pades.PAdESSignatureParameters; //导入方法依赖的package包/类
/**
 * Private method to set up parameters of signature
 *
 * @param certificateBase64 certificate string encoded in base64
 * @return PAdESSignatureParameters parameters
 */
private PAdESSignatureParameters getParameters(String certificateBase64) {
    byte[] certificate = Base64.getDecoder().decode(certificateBase64);

    CertificateToken token = DSSUtils.loadCertificate(certificate);

    PAdESSignatureParameters parameters = new PAdESSignatureParameters();
    parameters.setSignatureLevel(SignatureLevel.PAdES_BASELINE_B);
    parameters.setSignaturePackaging(SignaturePackaging.ENVELOPED);
    parameters.setDigestAlgorithm(digestAlgorithm);
    parameters.setEncryptionAlgorithm(token.getEncryptionAlgorithm());
    parameters.setSigningCertificate(token);
    parameters.bLevel().setSigningDate(Date.from(Instant.now()));

    return parameters;
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:22,代码来源:PdfSigner.java

示例2: main

import eu.europa.esig.dss.pades.PAdESSignatureParameters; //导入方法依赖的package包/类
public static void main(final String[] args) throws IOException {
	// GET document to be signed -
	// Return DSSDocument toSignDocument
	preparePdfDoc();

	// Get a token connection based on a pkcs12 file commonly used to store private
	// keys with accompanying public key certificates, protected with a password-based
	// symmetric key -
	// Return AbstractSignatureTokenConnection signingToken

	// and it's first private key entry from the PKCS12 store
	// Return DSSPrivateKeyEntry privateKey *****
	preparePKCS12TokenAndKey();

	// Preparing parameters for the PAdES signature
	PAdESSignatureParameters parameters = new PAdESSignatureParameters();
	// We choose the level of the signature (-B, -T, -LT, -LTA).
	parameters.setSignatureLevel(SignatureLevel.PAdES_BASELINE_B);
	// We choose the type of the signature packaging (ENVELOPING, DETACHED).
	parameters.setSignaturePackaging(SignaturePackaging.DETACHED);
	// 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 CAdES xadesService for signature
	PAdESService service = new PAdESService(commonCertificateVerifier);

	// Get the SignedInfo 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);

	// We use the DSSUtils to Save to file
	signedDocument.save("target/signedPdfPadesBDetached.pdf");
}
 
开发者ID:esig,项目名称:dss,代码行数:51,代码来源:SignPdfPadesBDetached.java

示例3: signPAdESBaselineBWithVisibleSignature

import eu.europa.esig.dss.pades.PAdESSignatureParameters; //导入方法依赖的package包/类
@Test
public void signPAdESBaselineBWithVisibleSignature() throws IOException {

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

	// Get a token connection based on a pkcs12 file commonly used to store private
	// keys with accompanying public key certificates, protected with a password-based
	// symmetric key -
	// Return AbstractSignatureTokenConnection signingToken

	// and it's first private key entry from the PKCS12 store
	// Return DSSPrivateKeyEntry privateKey *****
	preparePKCS12TokenAndKey();

	// tag::demo[]

	// Preparing parameters for the PAdES signature
	PAdESSignatureParameters parameters = new PAdESSignatureParameters();
	// We choose the level of the signature (-B, -T, -LT, -LTA).
	parameters.setSignatureLevel(SignatureLevel.PAdES_BASELINE_B);
	// We choose the type of the signature packaging (ENVELOPING, DETACHED).
	parameters.setSignaturePackaging(SignaturePackaging.ENVELOPED);

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

	// Initialize visual signature
	SignatureImageParameters imageParameters = new SignatureImageParameters();
	// the origin is the left and top corner of the page
	imageParameters.setxAxis(200);
	imageParameters.setyAxis(500);

	// Initialize text to generate for visual signature
	SignatureImageTextParameters textParameters = new SignatureImageTextParameters();
	textParameters.setFont(new Font("serif", Font.PLAIN, 14));
	textParameters.setTextColor(Color.BLUE);
	textParameters.setText("My visual signature");
	imageParameters.setTextParameters(textParameters);

	parameters.setSignatureImageParameters(imageParameters);

	// Create common certificate verifier
	CommonCertificateVerifier commonCertificateVerifier = new CommonCertificateVerifier();
	// Create PAdESService for signature
	PAdESService service = new PAdESService(commonCertificateVerifier);

	// Get the SignedInfo 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);

	// end::demo[]

	testFinalDocument(signedDocument);
}
 
开发者ID:esig,项目名称:dss,代码行数:67,代码来源:SignPdfPadesBVisibleTest.java

示例4: signPAdESBaselineB

import eu.europa.esig.dss.pades.PAdESSignatureParameters; //导入方法依赖的package包/类
@Test
public void signPAdESBaselineB() throws IOException {

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

	// Get a token connection based on a pkcs12 file commonly used to store private
	// keys with accompanying public key certificates, protected with a password-based
	// symmetric key -
	// Return AbstractSignatureTokenConnection signingToken

	// and it's first private key entry from the PKCS12 store
	// Return DSSPrivateKeyEntry privateKey *****
	preparePKCS12TokenAndKey();

	// tag::demo[]

	// Preparing parameters for the PAdES signature
	PAdESSignatureParameters parameters = new PAdESSignatureParameters();
	// We choose the level of the signature (-B, -T, -LT, -LTA).
	parameters.setSignatureLevel(SignatureLevel.PAdES_BASELINE_B);
	// We choose the type of the signature packaging (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 PAdESService for signature
	PAdESService service = new PAdESService(commonCertificateVerifier);

	// Get the SignedInfo 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);

	// end::demo[]

	testFinalDocument(signedDocument);
}
 
开发者ID:esig,项目名称:dss,代码行数:56,代码来源:SignPdfPadesBTest.java

示例5: signPAdESBaselineBWithExistingVisibleSignature

import eu.europa.esig.dss.pades.PAdESSignatureParameters; //导入方法依赖的package包/类
@Test
public void signPAdESBaselineBWithExistingVisibleSignature() throws IOException {

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

	// Get a token connection based on a pkcs12 file commonly used to store private
	// keys with accompanying public key certificates, protected with a password-based
	// symmetric key -
	// Return AbstractSignatureTokenConnection signingToken

	// Return DSSPrivateKeyEntry privateKey from the PKCS12 store
	preparePKCS12TokenAndKey();

	// tag::demo[]

	// Preparing parameters for the PAdES signature
	PAdESSignatureParameters parameters = new PAdESSignatureParameters();
	parameters.bLevel().setSigningDate(new Date());
	// We choose the level of the signature (-B, -T, -LT, -LTA).
	parameters.setSignatureLevel(SignatureLevel.PAdES_BASELINE_B);
	// We choose the type of the signature packaging (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());

	// Initialize visual signature
	SignatureImageParameters imageParameters = new SignatureImageParameters();
	// the origin is the left and top corner of the page
	imageParameters.setxAxis(200);
	imageParameters.setyAxis(500);
	// Initialize text to generate for visual signature
	SignatureImageTextParameters textParameters = new SignatureImageTextParameters();
	textParameters.setFont(new Font("serif", Font.PLAIN, 14));
	textParameters.setTextColor(Color.BLUE);
	textParameters.setText("My visual signature");
	imageParameters.setTextParameters(textParameters);
	parameters.setSignatureImageParameters(imageParameters);
	
	parameters.setSignatureFieldId("ExistingSignatureField");
			
	// Create common certificate verifier
	CommonCertificateVerifier commonCertificateVerifier = new CommonCertificateVerifier();
	// Create PAdESService for signature
	PAdESService service = new PAdESService(commonCertificateVerifier);

	// Get the SignedInfo 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 padesService to sign the document with the signature value obtained in
	// the previous step.
	DSSDocument signedDocument = service.signDocument(toSignDocument, parameters, signatureValue);
	
	// end::demo[]
	testFinalDocument(signedDocument);
}
 
开发者ID:esig,项目名称:dss,代码行数:70,代码来源:SignPdfPadesBVisibleExisting.java


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