AsiceWithXadesSignatureService implements SignatureService { @Override public byte[] getSignature(byte[] dataToSign, String dataName, String mimeTypeString) throws IOException { if (properties == null) { throw new SignatureServiceException("Signature configuration properties not set!"); } AbstractSignatureTokenConnection signatureToken = getSignatureToken(properties); DSSPrivateKeyEntry privateKeyEntry = signatureToken.getKeys().get(0); ASiCWithXAdESSignatureParameters parameters = new ASiCWithXAdESSignatureParameters(); SignatureLevel signatureLevel = getSingatureLevel(properties.getSignatureLevel()); parameters.setSignatureLevel(signatureLevel); parameters.setSignaturePackaging(SignaturePackaging.DETACHED); parameters.aSiC().setContainerType(ASiCContainerType.ASiC_E); parameters.setDigestAlgorithm(DigestAlgorithm.SHA256); parameters.aSiC().setMimeType(MimeType.ASICE.getMimeTypeString()); parameters.setSigningCertificate(privateKeyEntry.getCertificate()); parameters.setEncryptionAlgorithm(privateKeyEntry.getEncryptionAlgorithm()); CommonCertificateVerifier commonCertificateVerifier = new CommonCertificateVerifier(); OCSPSource ocspSource = getOcspSource(properties.getOcspUrl()); commonCertificateVerifier.setOcspSource(ocspSource); commonCertificateVerifier.setTrustedCertSource(trustedListSource); ASiCWithXAdESService service = new ASiCWithXAdESService(commonCertificateVerifier); TSPSource tspSource = getTspSource(properties.getTspUrl()); service.setTspSource(tspSource); DSSDocument documentToBeSigned = new InMemoryDocument(dataToSign, dataName); MimeType mimeType = new MimeType(); mimeType.setMimeTypeString(mimeTypeString); documentToBeSigned.setMimeType(mimeType); ToBeSigned toBeSigned = service.getDataToSign(documentToBeSigned, parameters); SignatureValue signatureValue = signatureToken.sign(toBeSigned, parameters.getDigestAlgorithm(), privateKeyEntry); DSSDocument signedDocument = service.signDocument(documentToBeSigned, parameters, signatureValue); return IOUtils.toByteArray(signedDocument.openStream()); }  @Override byte[] getSignature(byte[] dataToSign, String dataName, String mimeTypeString); SignatureServiceConfigurationProperties getProperties(); void setProperties(SignatureServiceConfigurationProperties signatureServiceConfigurationProperties);  }
@Test public void AsiceSignatureServiceConfiguredCorrectly_withXadesBaselineProfileB_shouldPass() throws IOException { byte[] signature = asiceSignatureService.getSignature("Hello".getBytes(), "hello.txt", "application/text"); assertNotNull(signature); }