本文整理汇总了Java中eu.europa.esig.dss.BLevelParameters类的典型用法代码示例。如果您正苦于以下问题:Java BLevelParameters类的具体用法?Java BLevelParameters怎么用?Java BLevelParameters使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BLevelParameters类属于eu.europa.esig.dss包,在下文中一共展示了BLevelParameters类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildParameters
import eu.europa.esig.dss.BLevelParameters; //导入依赖的package包/类
private RemoteSignatureParameters buildParameters(DSSPrivateKeyEntry signer) {
updateProgress(20, 100);
RemoteSignatureParameters parameters = new RemoteSignatureParameters();
parameters.setAsicContainerType(model.getAsicContainerType());
parameters.setDigestAlgorithm(model.getDigestAlgorithm());
parameters.setSignatureLevel(model.getSignatureLevel());
parameters.setSignaturePackaging(model.getSignaturePackaging());
BLevelParameters bLevelParams = new BLevelParameters();
bLevelParams.setSigningDate(new Date());
parameters.setBLevelParams(bLevelParams);
parameters.setSigningCertificate(new RemoteCertificate(signer.getCertificate().getEncoded()));
parameters.setEncryptionAlgorithm(signer.getEncryptionAlgorithm());
CertificateToken[] certificateChain = signer.getCertificateChain();
if (Utils.isArrayNotEmpty(certificateChain)) {
List<RemoteCertificate> certificateChainList = new ArrayList<RemoteCertificate>();
for (CertificateToken certificateToken : certificateChain) {
certificateChainList.add(new RemoteCertificate(certificateToken.getEncoded()));
}
parameters.setCertificateChain(certificateChainList);
}
return parameters;
}
示例2: getDataToSignOneDocument
import eu.europa.esig.dss.BLevelParameters; //导入依赖的package包/类
@Test
public void getDataToSignOneDocument() throws Exception {
DSSPrivateKeyEntry dssPrivateKeyEntry = token.getKeys().get(0);
DataToSignOneDocumentDTO dataToSign = new DataToSignOneDocumentDTO();
RemoteSignatureParameters parameters = new RemoteSignatureParameters();
parameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B);
parameters.setSignaturePackaging(SignaturePackaging.ENVELOPING);
parameters.setDigestAlgorithm(DigestAlgorithm.SHA256);
parameters.setSigningCertificate(new RemoteCertificate(dssPrivateKeyEntry.getCertificate().getEncoded()));
BLevelParameters bLevelParams = new BLevelParameters();
bLevelParams.setSigningDate(new Date());
parameters.setBLevelParams(bLevelParams);
dataToSign.setParameters(parameters);
RemoteDocument toSignDocument = new RemoteDocument();
toSignDocument.setBytes("Hello".getBytes("UTF-8"));
dataToSign.setToSignDocument(toSignDocument);
RestAssured.given(this.spec).accept(ContentType.JSON).contentType(ContentType.JSON).body(dataToSign, ObjectMapperType.JACKSON_2)
.post("/services/rest/signature/one-document/getDataToSign").then().assertThat().statusCode(equalTo(200));
}
示例3: addCommitmentType
import eu.europa.esig.dss.BLevelParameters; //导入依赖的package包/类
/**
* ETSI TS 101 733 V2.2.1 (2013-04)
*
* 5.11.1 commitment-type-indication Attribute
* There may be situations where a signer wants to explicitly indicate to a verifier that by signing the data, it
* illustrates a
* type of commitment on behalf of the signer. The commitment-type-indication attribute conveys such
* information.
*
* @param parameters
* @param signedAttributes
*/
private void addCommitmentType(final CAdESSignatureParameters parameters, final ASN1EncodableVector signedAttributes) {
// TODO (19/08/2014): commitmentTypeQualifier is not implemented
final BLevelParameters bLevelParameters = parameters.bLevel();
final List<String> commitmentTypeIndications = bLevelParameters.getCommitmentTypeIndications();
if (Utils.isCollectionNotEmpty(commitmentTypeIndications)) {
final int size = commitmentTypeIndications.size();
ASN1Encodable[] asn1Encodables = new ASN1Encodable[size];
for (int ii = 0; ii < size; ii++) {
final String commitmentTypeId = commitmentTypeIndications.get(ii);
final ASN1ObjectIdentifier objectIdentifier = new ASN1ObjectIdentifier(commitmentTypeId);
// final CommitmentTypeIndication commitmentTypeIndication = new
// CommitmentTypeIndication(objectIdentifier);
// final ASN1Primitive asn1Primitive = commitmentTypeIndication.toASN1Primitive();
asn1Encodables[ii] = new DERSequence(objectIdentifier);
}
final DERSet attrValues = new DERSet(asn1Encodables);
final Attribute attribute = new Attribute(id_aa_ets_commitmentType, attrValues);
signedAttributes.add(attribute);
}
}
示例4: signDocumentOneDocument
import eu.europa.esig.dss.BLevelParameters; //导入依赖的package包/类
@Test
public void signDocumentOneDocument() throws Exception {
DSSPrivateKeyEntry dssPrivateKeyEntry = token.getKeys().get(0);
SignOneDocumentDTO signOneDoc = new SignOneDocumentDTO();
RemoteSignatureParameters parameters = new RemoteSignatureParameters();
parameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B);
parameters.setSignaturePackaging(SignaturePackaging.ENVELOPING);
parameters.setDigestAlgorithm(DigestAlgorithm.SHA256);
parameters.setSigningCertificate(new RemoteCertificate(dssPrivateKeyEntry.getCertificate().getEncoded()));
BLevelParameters bLevelParams = new BLevelParameters();
bLevelParams.setSigningDate(new Date());
parameters.setBLevelParams(bLevelParams);
signOneDoc.setParameters(parameters);
RemoteDocument toSignDocument = new RemoteDocument();
toSignDocument.setBytes("Hello".getBytes("UTF-8"));
signOneDoc.setToSignDocument(toSignDocument);
signOneDoc.setSignatureValue(new SignatureValue(SignatureAlgorithm.RSA_SHA256, new byte[] { 1, 2, 3, 4 }));
RestAssured.given(this.spec).accept(ContentType.JSON).contentType(ContentType.JSON).body(signOneDoc, ObjectMapperType.JACKSON_2)
.post("/services/rest/signature/one-document/signDocument").then().assertThat().statusCode(equalTo(200));
}
示例5: getDataToSignMultiDocuments
import eu.europa.esig.dss.BLevelParameters; //导入依赖的package包/类
@Test
public void getDataToSignMultiDocuments() throws Exception {
DSSPrivateKeyEntry dssPrivateKeyEntry = token.getKeys().get(0);
DataToSignMultipleDocumentsDTO dataToSignMultiDocs = new DataToSignMultipleDocumentsDTO();
RemoteSignatureParameters parameters = new RemoteSignatureParameters();
parameters.setAsicContainerType(ASiCContainerType.ASiC_E);
parameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B);
parameters.setSignaturePackaging(SignaturePackaging.DETACHED);
parameters.setDigestAlgorithm(DigestAlgorithm.SHA256);
parameters.setSigningCertificate(new RemoteCertificate(dssPrivateKeyEntry.getCertificate().getEncoded()));
BLevelParameters bLevelParams = new BLevelParameters();
bLevelParams.setSigningDate(new Date());
parameters.setBLevelParams(bLevelParams);
dataToSignMultiDocs.setParameters(parameters);
List<RemoteDocument> toSignDocuments = new ArrayList<RemoteDocument>();
RemoteDocument doc1 = new RemoteDocument();
doc1.setBytes("Hello".getBytes("UTF-8"));
doc1.setName("test1.bin");
toSignDocuments.add(doc1);
RemoteDocument doc2 = new RemoteDocument();
doc2.setBytes("World".getBytes("UTF-8"));
doc2.setName("test2.bin");
toSignDocuments.add(doc2);
dataToSignMultiDocs.setToSignDocuments(toSignDocuments);
RestAssured.given(this.spec).accept(ContentType.JSON).contentType(ContentType.JSON).body(dataToSignMultiDocs, ObjectMapperType.JACKSON_2)
.post("/services/rest/signature/multiple-documents/getDataToSignMultiple").then().assertThat().statusCode(equalTo(200));
}
示例6: signDocumentMultiDocuments
import eu.europa.esig.dss.BLevelParameters; //导入依赖的package包/类
@Test
public void signDocumentMultiDocuments() throws Exception {
DSSPrivateKeyEntry dssPrivateKeyEntry = token.getKeys().get(0);
SignMultipleDocumentDTO signMultiDocsDto = new SignMultipleDocumentDTO();
RemoteSignatureParameters parameters = new RemoteSignatureParameters();
parameters.setAsicContainerType(ASiCContainerType.ASiC_E);
parameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B);
parameters.setSignaturePackaging(SignaturePackaging.DETACHED);
parameters.setDigestAlgorithm(DigestAlgorithm.SHA256);
parameters.setSigningCertificate(new RemoteCertificate(dssPrivateKeyEntry.getCertificate().getEncoded()));
BLevelParameters bLevelParams = new BLevelParameters();
bLevelParams.setSigningDate(new Date());
parameters.setBLevelParams(bLevelParams);
signMultiDocsDto.setParameters(parameters);
List<RemoteDocument> toSignDocuments = new ArrayList<RemoteDocument>();
RemoteDocument doc1 = new RemoteDocument();
doc1.setBytes("Hello".getBytes("UTF-8"));
doc1.setName("test1.bin");
toSignDocuments.add(doc1);
RemoteDocument doc2 = new RemoteDocument();
doc2.setBytes("World".getBytes("UTF-8"));
doc2.setName("test2.bin");
toSignDocuments.add(doc2);
signMultiDocsDto.setToSignDocuments(toSignDocuments);
signMultiDocsDto.setSignatureValue(new SignatureValue(SignatureAlgorithm.RSA_SHA256, new byte[] { 1, 2, 3, 4 }));
RestAssured.given(this.spec).accept(ContentType.JSON).contentType(ContentType.JSON).body(signMultiDocsDto, ObjectMapperType.JACKSON_2)
.post("/services/rest/signature/multiple-documents/signDocument").then().assertThat().statusCode(equalTo(200));
}
示例7: getGetDataToSignHelper
import eu.europa.esig.dss.BLevelParameters; //导入依赖的package包/类
public static GetDataToSignASiCWithCAdESHelper getGetDataToSignHelper(List<DSSDocument> documents, ASiCWithCAdESSignatureParameters parameters) {
BLevelParameters bLevel = parameters.bLevel();
boolean asice = ASiCUtils.isASiCE(parameters.aSiC());
boolean archive = ASiCUtils.isArchive(documents);
if (archive) {
DSSDocument archiveDoc = documents.get(0);
if (!ASiCUtils.isArchiveContainsCorrectSignatureExtension(archiveDoc, ".p7s")) {
throw new UnsupportedOperationException("Container type doesn't match");
}
ASiCWithCAdESContainerExtractor extractor = new ASiCWithCAdESContainerExtractor(archiveDoc);
ASiCExtractResult extract = extractor.extract();
if (asice) {
return new DataToSignASiCEWithCAdESFromArchive(extract.getSignedDocuments(), extract.getSignatureDocuments(), extract.getManifestDocuments(),
parameters);
} else {
return new DataToSignASiCSWithCAdESFromArchive(extract.getSignatureDocuments(), extract.getSignedDocuments(), parameters.aSiC());
}
} else {
if (asice) {
return new DataToSignASiCEWithCAdESFromFiles(documents, parameters);
} else {
return new DataToSignASiCSWithCAdESFromFiles(documents, bLevel.getSigningDate(), parameters.aSiC());
}
}
}
示例8: getGetDataToSignHelper
import eu.europa.esig.dss.BLevelParameters; //导入依赖的package包/类
public static GetDataToSignASiCWithXAdESHelper getGetDataToSignHelper(List<DSSDocument> documents, ASiCWithXAdESSignatureParameters parameters) {
BLevelParameters bLevel = parameters.bLevel();
boolean asice = ASiCUtils.isASiCE(parameters.aSiC());
boolean archive = ASiCUtils.isArchive(documents);
if (archive) {
DSSDocument archiveDoc = documents.get(0);
if (!ASiCUtils.isArchiveContainsCorrectSignatureExtension(archiveDoc, ".xml")) {
throw new UnsupportedOperationException("Container type doesn't match");
}
ASiCWithXAdESContainerExtractor extractor = new ASiCWithXAdESContainerExtractor(archiveDoc);
ASiCExtractResult extract = extractor.extract();
if (asice) {
return new DataToSignASiCEWithXAdESFromArchive(extract.getSignedDocuments(), extract.getSignatureDocuments(), extract.getManifestDocuments(),
parameters.aSiC());
} else {
return new DataToSignASiCSWithXAdESFromArchive(extract.getSignatureDocuments(), extract.getSignedDocuments(), parameters.aSiC());
}
} else {
if (asice) {
return new DataToSignASiCEWithXAdESFromFiles(documents, parameters.aSiC());
} else {
return new DataToSignASiCSWithXAdESFromFiles(documents, bLevel.getSigningDate(), parameters.aSiC());
}
}
}
示例9: testWithExplicitPolicy
import eu.europa.esig.dss.BLevelParameters; //导入依赖的package包/类
@Test
public void testWithExplicitPolicy() throws IOException {
prepareXmlDoc();
preparePKCS12TokenAndKey();
// tag::demo[]
XAdESSignatureParameters parameters = new XAdESSignatureParameters();
parameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B);
parameters.setSignaturePackaging(SignaturePackaging.ENVELOPED);
parameters.setDigestAlgorithm(DigestAlgorithm.SHA256);
// We set the signing certificate
parameters.setSigningCertificate(privateKey.getCertificate());
// We set the certificate chain
parameters.setCertificateChain(privateKey.getCertificateChain());
BLevelParameters bLevelParameters = parameters.bLevel();
// Get and use the explicit policy
String signaturePolicyId = "http://www.example.com/policy.txt";
DigestAlgorithm signaturePolicyHashAlgo = DigestAlgorithm.SHA256;
String signaturePolicyDescription = "Policy text to digest";
byte[] signaturePolicyDescriptionBytes = signaturePolicyDescription.getBytes();
byte[] digestedBytes = DSSUtils.digest(signaturePolicyHashAlgo, signaturePolicyDescriptionBytes);
Policy policy = new Policy();
policy.setId(signaturePolicyId);
policy.setDigestAlgorithm(signaturePolicyHashAlgo);
policy.setDigestValue(digestedBytes);
bLevelParameters.setSignaturePolicy(policy);
// Create common certificate verifier
CommonCertificateVerifier commonCertificateVerifier = new CommonCertificateVerifier();
// Create xadesService for signature
XAdESService service = new XAdESService(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);
}
示例10: testWithImplicitPolicy
import eu.europa.esig.dss.BLevelParameters; //导入依赖的package包/类
@Test
public void testWithImplicitPolicy() throws IOException {
prepareXmlDoc();
preparePKCS12TokenAndKey();
// tag::demo[]
XAdESSignatureParameters parameters = new XAdESSignatureParameters();
parameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B);
parameters.setSignaturePackaging(SignaturePackaging.ENVELOPED);
parameters.setDigestAlgorithm(DigestAlgorithm.SHA256);
// We set the signing certificate
parameters.setSigningCertificate(privateKey.getCertificate());
// We set the certificate chain
parameters.setCertificateChain(privateKey.getCertificateChain());
BLevelParameters bLevelParameters = parameters.bLevel();
Policy policy = new Policy();
policy.setId("");
bLevelParameters.setSignaturePolicy(policy);
// Create common certificate verifier
CommonCertificateVerifier commonCertificateVerifier = new CommonCertificateVerifier();
// Create xadesService for signature
XAdESService service = new XAdESService(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);
}
示例11: testWithProperties
import eu.europa.esig.dss.BLevelParameters; //导入依赖的package包/类
@Test
public void testWithProperties() throws IOException {
prepareXmlDoc();
preparePKCS12TokenAndKey();
// tag::demo[]
XAdESSignatureParameters parameters = new XAdESSignatureParameters();
parameters.setSignaturePackaging(SignaturePackaging.ENVELOPED);
parameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B);
parameters.setDigestAlgorithm(DigestAlgorithm.SHA512);
parameters.setSigningCertificate(privateKey.getCertificate());
parameters.setCertificateChain(privateKey.getCertificateChain());
BLevelParameters bLevelParameters = parameters.bLevel();
bLevelParameters.setClaimedSignerRoles(Arrays.asList("My Claimed Role"));
SignerLocation signerLocation = new SignerLocation();
signerLocation.setCountry("BE");
signerLocation.setStateOrProvince("Luxembourg");
signerLocation.setPostalCode("1234");
signerLocation.setLocality("SimCity");
bLevelParameters.setSignerLocation(signerLocation);
List<String> commitmentTypeIndications = new ArrayList<String>();
commitmentTypeIndications.add("http://uri.etsi.org/01903/v1.2.2#ProofOfOrigin");
commitmentTypeIndications.add("http://uri.etsi.org/01903/v1.2.2#ProofOfApproval");
bLevelParameters.setCommitmentTypeIndications(commitmentTypeIndications);
CommonCertificateVerifier verifier = new CommonCertificateVerifier();
XAdESService service = new XAdESService(verifier);
ToBeSigned dataToSign = service.getDataToSign(toSignDocument, parameters);
SignatureValue signatureValue = signingToken.sign(dataToSign, parameters.getDigestAlgorithm(), privateKey);
DSSDocument signedDocument = service.signDocument(toSignDocument, parameters, signatureValue);
// end::demo[]
testFinalDocument(signedDocument);
}
示例12: setSignerRoles
import eu.europa.esig.dss.BLevelParameters; //导入依赖的package包/类
public void setSignerRoles(Collection<String> signerRoles) {
BLevelParameters bLevelParameters = xAdESSignatureParameters.bLevel();
for (String signerRole : signerRoles) {
bLevelParameters.addClaimedSignerRole(signerRole);
}
}