本文整理汇总了Java中eu.europa.esig.dss.utils.Utils.toByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java Utils.toByteArray方法的具体用法?Java Utils.toByteArray怎么用?Java Utils.toByteArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eu.europa.esig.dss.utils.Utils
的用法示例。
在下文中一共展示了Utils.toByteArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSigningAndExtensionMultiDocuments
import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
@Test
public void testSigningAndExtensionMultiDocuments() throws Exception {
CertificateService certificateService = new CertificateService();
MockPrivateKeyEntry entry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256);
RemoteSignatureParameters parameters = new RemoteSignatureParameters();
parameters.setAsicContainerType(ASiCContainerType.ASiC_E);
parameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B);
parameters.setSigningCertificate(new RemoteCertificate(entry.getCertificate().getCertificate().getEncoded()));
parameters.setDigestAlgorithm(DigestAlgorithm.SHA256);
FileDocument fileToSign = new FileDocument(new File("src/test/resources/sample.xml"));
RemoteDocument toSignDocument = new RemoteDocument(Utils.toByteArray(fileToSign.openStream()), fileToSign.getMimeType(), fileToSign.getName(),
fileToSign.getAbsolutePath());
RemoteDocument toSignDoc2 = new RemoteDocument("Hello world!".getBytes("UTF-8"), MimeType.BINARY, "test.bin");
List<RemoteDocument> toSignDocuments = new ArrayList<RemoteDocument>();
toSignDocuments.add(toSignDocument);
toSignDocuments.add(toSignDoc2);
ToBeSigned dataToSign = restMultiDocsClient.getDataToSign(new DataToSignMultipleDocumentsDTO(toSignDocuments, parameters));
assertNotNull(dataToSign);
SignatureValue signatureValue = TestUtils.sign(SignatureAlgorithm.RSA_SHA256, entry, dataToSign);
SignMultipleDocumentDTO signDocument = new SignMultipleDocumentDTO(toSignDocuments, parameters, signatureValue);
RemoteDocument signedDocument = restMultiDocsClient.signDocument(signDocument);
assertNotNull(signedDocument);
parameters = new RemoteSignatureParameters();
parameters.setAsicContainerType(ASiCContainerType.ASiC_E);
parameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_T);
RemoteDocument extendedDocument = restMultiDocsClient.extendDocument(new ExtendDocumentDTO(signedDocument, parameters));
assertNotNull(extendedDocument);
InMemoryDocument iMD = new InMemoryDocument(extendedDocument.getBytes());
iMD.save("target/test.asice");
}
示例2: call
import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
@Override
protected DSSDocument call() throws Exception {
updateProgress(0, 100);
SignatureTokenConnection token = getToken(model);
updateProgress(5, 100);
List<DSSPrivateKeyEntry> keys = token.getKeys();
updateProgress(10, 100);
DSSPrivateKeyEntry signer = getSigner(keys);
FileDocument fileToSign = new FileDocument(model.getFileToSign());
RemoteDocument toSignDocument = new RemoteDocument(Utils.toByteArray(fileToSign.openStream()), fileToSign.getMimeType(), fileToSign.getName(),
fileToSign.getAbsolutePath());
RemoteSignatureParameters parameters = buildParameters(signer);
ToBeSigned toBeSigned = getDataToSign(toSignDocument, parameters);
SignatureValue signatureValue = signDigest(token, signer, toBeSigned);
DSSDocument signDocument = signDocument(toSignDocument, parameters, signatureValue);
updateProgress(100, 100);
return signDocument;
}
示例3: init
import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
@Before
public void init() throws Exception {
File file = new File("src/test/resources/sample.xml");
FileInputStream fis = new FileInputStream(file);
byte[] bytes = Utils.toByteArray(fis);
Utils.closeQuietly(fis);
String computedDigest = Utils.toBase64(DSSUtils.digest(DigestAlgorithm.SHA256, bytes));
DigestDocument digestDocument = new DigestDocument();
digestDocument.setName("sample.xml");
digestDocument.addDigest(DigestAlgorithm.SHA256, computedDigest);
documentToSign = digestDocument;
signatureParameters = new XAdESSignatureParameters();
signatureParameters.bLevel().setSigningDate(new Date());
signatureParameters.setSigningCertificate(getSigningCert());
signatureParameters.setCertificateChain(getCertificateChain());
signatureParameters.setSignaturePackaging(SignaturePackaging.DETACHED);
signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B);
service = new XAdESService(getCompleteCertificateVerifier());
}
示例4: getValidationReport
import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
@Override
protected Reports getValidationReport(final DSSDocument signedDocument) {
SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument);
validator.setCertificateVerifier(getCompleteCertificateVerifier());
InMemoryDocument inMemoryDocument = new InMemoryDocument("Hello World !".getBytes(), "test.text");
byte[] bytes;
try {
bytes = Utils.toByteArray(inMemoryDocument.openStream());
} catch (Exception e) {
throw new DSSException(e);
}
DigestDocument digestDocument = new DigestDocument();
digestDocument.addDigest(DigestAlgorithm.SHA256, Utils.toBase64(DSSUtils.digest(DigestAlgorithm.SHA256, bytes)));
List<DSSDocument> detachedContents = new ArrayList<DSSDocument>();
detachedContents.add(digestDocument);
validator.setDetachedContents(detachedContents);
return validator.validateDocument();
}
示例5: getDigestSignaturePolicy
import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
@Test
public void getDigestSignaturePolicy() throws Exception {
FileInputStream fis = new FileInputStream("src/test/resources/signature-policy-example.der");
byte[] policyBytes = Utils.toByteArray(fis);
Utils.closeQuietly(fis);
byte[] signaturePolicyDigest = DSSASN1Utils.getAsn1SignaturePolicyDigest(DigestAlgorithm.SHA256, policyBytes);
String hexSignaturePolicyDigest = Utils.toHex(signaturePolicyDigest);
assertEquals("fe71e01aedd99f444238602d4e98f47bbab405c58c0e3811b9511dcd58c3c983", hexSignaturePolicyDigest);
}
示例6: testSigningAndExtension
import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
@Test
public void testSigningAndExtension() throws Exception {
CertificateService certificateService = new CertificateService();
MockPrivateKeyEntry entry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256);
RemoteSignatureParameters parameters = new RemoteSignatureParameters();
parameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B);
parameters.setSigningCertificate(new RemoteCertificate(entry.getCertificate().getCertificate().getEncoded()));
parameters.setSignaturePackaging(SignaturePackaging.ENVELOPING);
parameters.setDigestAlgorithm(DigestAlgorithm.SHA256);
FileDocument fileToSign = new FileDocument(new File("src/test/resources/sample.xml"));
RemoteDocument toSignDocument = new RemoteDocument(Utils.toByteArray(fileToSign.openStream()), fileToSign.getMimeType(), fileToSign.getName(),
fileToSign.getAbsolutePath());
ToBeSigned dataToSign = restClient.getDataToSign(new DataToSignOneDocumentDTO(toSignDocument, parameters));
assertNotNull(dataToSign);
SignatureValue signatureValue = TestUtils.sign(SignatureAlgorithm.RSA_SHA256, entry, dataToSign);
SignOneDocumentDTO signDocument = new SignOneDocumentDTO(toSignDocument, parameters, signatureValue);
RemoteDocument signedDocument = restClient.signDocument(signDocument);
assertNotNull(signedDocument);
parameters = new RemoteSignatureParameters();
parameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_T);
RemoteDocument extendedDocument = restClient.extendDocument(new ExtendDocumentDTO(signedDocument, parameters));
assertNotNull(extendedDocument);
InMemoryDocument iMD = new InMemoryDocument(extendedDocument.getBytes());
iMD.save("target/test.xml");
}
示例7: testSigningAndExtension
import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
@Test
public void testSigningAndExtension() throws Exception {
CertificateService certificateService = new CertificateService();
MockPrivateKeyEntry entry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256);
RemoteSignatureParameters parameters = new RemoteSignatureParameters();
parameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B);
parameters.setSigningCertificate(new RemoteCertificate(entry.getCertificate().getCertificate().getEncoded()));
parameters.setSignaturePackaging(SignaturePackaging.ENVELOPING);
parameters.setDigestAlgorithm(DigestAlgorithm.SHA256);
FileDocument fileToSign = new FileDocument(new File("src/test/resources/sample.xml"));
RemoteDocument toSignDocument = new RemoteDocument(Utils.toByteArray(fileToSign.openStream()), fileToSign.getMimeType(), fileToSign.getName(),
fileToSign.getAbsolutePath());
ToBeSigned dataToSign = soapClient.getDataToSign(new DataToSignOneDocumentDTO(toSignDocument, parameters));
assertNotNull(dataToSign);
SignatureValue signatureValue = TestUtils.sign(SignatureAlgorithm.RSA_SHA256, entry, dataToSign);
SignOneDocumentDTO signDocument = new SignOneDocumentDTO(toSignDocument, parameters, signatureValue);
RemoteDocument signedDocument = soapClient.signDocument(signDocument);
assertNotNull(signedDocument);
parameters = new RemoteSignatureParameters();
parameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_T);
RemoteDocument extendedDocument = soapClient.extendDocument(new ExtendDocumentDTO(signedDocument, parameters));
assertNotNull(extendedDocument);
InMemoryDocument iMD = new InMemoryDocument(extendedDocument.getBytes());
iMD.save("target/test.xml");
}
示例8: testXmlUTF8InMemory
import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
@Test
public void testXmlUTF8InMemory() throws IOException {
FileInputStream fis = new FileInputStream(new File("src/test/resources/sample.xml"));
byte[] byteArray = Utils.toByteArray(fis);
Utils.closeQuietly(fis);
DSSDocument document = new InMemoryDocument(byteArray);
SignedDocumentValidator documentValidator = SignedDocumentValidator.fromDocument(document);
assertTrue(documentValidator instanceof XMLDocumentValidator);
}
示例9: testXmlUISOInMemory
import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
@Test
public void testXmlUISOInMemory() throws IOException {
FileInputStream fis = new FileInputStream(new File("src/test/resources/sampleISO.xml"));
byte[] byteArray = Utils.toByteArray(fis);
Utils.closeQuietly(fis);
DSSDocument document = new InMemoryDocument(byteArray);
SignedDocumentValidator documentValidator = SignedDocumentValidator.fromDocument(document);
assertTrue(documentValidator instanceof XMLDocumentValidator);
}
示例10: signAndVerify
import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
@Test
public void signAndVerify() throws IOException {
final DSSDocument signedDocument = sign();
assertNotNull(signedDocument.getName());
assertNotNull(DSSUtils.toByteArray(signedDocument));
assertNotNull(signedDocument.getMimeType());
LOG.info("=================== VALIDATION =================");
// signedDocument.save("target/" + signedDocument.getName());
try {
byte[] byteArray = Utils.toByteArray(signedDocument.openStream());
onDocumentSigned(byteArray);
if (LOG.isDebugEnabled()) {
LOG.debug(new String(byteArray));
}
} catch (Exception e) {
LOG.error("Cannot display file content", e);
}
checkMimeType(signedDocument);
Reports reports = getValidationReport(signedDocument);
// reports.setValidateXml(true);
// reports.print();
DiagnosticData diagnosticData = reports.getDiagnosticData();
verifyDiagnosticData(diagnosticData);
SimpleReport simpleReport = reports.getSimpleReport();
verifySimpleReport(simpleReport);
DetailedReport detailedReport = reports.getDetailedReport();
verifyDetailedReport(detailedReport);
}
示例11: toByteArray
import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
/**
* Get the contents of an {@code InputStream} as a {@code byte[]}.
*
* @param inputStream
* @return
*/
public static byte[] toByteArray(final InputStream inputStream) {
if (inputStream == null) {
throw new NullPointerException();
}
try {
final byte[] bytes = Utils.toByteArray(inputStream);
return bytes;
} catch (IOException e) {
throw new DSSException(e);
}
}
示例12: getOriginalDocumentBinaries
import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
public byte[] getOriginalDocumentBinaries() {
try (InputStream is = getOriginalDocumentStream()) {
return Utils.toByteArray(is);
} catch (Exception e) {
LOG.warn("Unable to retrieve original document binaries", e);
return DSSUtils.EMPTY_BYTE_ARRAY;
}
}
示例13: testFile3
import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
@Test
public void testFile3() throws DSSException, CMSException, IOException {
DSSDocument dssDocument = new FileDocument("src/test/resources/plugtest/esig2014/ESIG-CAdES/DE_CRY/Signature-C-DE_CRY-4.p7m");
CAdESSignature signature = new CAdESSignature(Utils.toByteArray(dssDocument.openStream()));
CMSSignedData cmsSignedData = signature.getCmsSignedData();
assertNotNull(cmsSignedData);
}
示例14: getOriginalDocumentFromEnvelopingSignature
import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
@Test
public final void getOriginalDocumentFromEnvelopingSignature() throws Exception {
DSSDocument document = new InMemoryDocument(HELLO_WORLD.getBytes());
CAdESSignatureParameters signatureParameters = new CAdESSignatureParameters();
signatureParameters.bLevel().setSigningDate(new Date());
signatureParameters.setSigningCertificate(getSigningCert());
signatureParameters.setCertificateChain(getCertificateChain());
signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING);
signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B);
CAdESService service = new CAdESService(getCompleteCertificateVerifier());
ToBeSigned dataToSign = service.getDataToSign(document, signatureParameters);
SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry());
final DSSDocument signedDocument = service.signDocument(document, signatureParameters, signatureValue);
SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument);
validator.setCertificateVerifier(getCompleteCertificateVerifier());
Reports reports = validator.validateDocument();
List<DSSDocument> results = validator.getOriginalDocuments(reports.getDiagnosticData().getFirstSignatureId());
Assert.assertEquals(1, results.size());
String firstDocument = new String(Utils.toByteArray(document.openStream()));
String secondDocument = new String(Utils.toByteArray(results.get(0).openStream()));
Assert.assertEquals(firstDocument, secondDocument);
}
示例15: get
import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
@Override
public byte[] get(final String urlString) {
if (urlString.equals("https://sede.060.gob.es/politica_de_firma_anexo_1.pdf")) {
DSSDocument document = new FileDocument("src/test/resources/validation/dss-728/politica_de_firma_anexo_1.pdf");
try {
return Utils.toByteArray(document.openStream());
} catch (IOException e) {
throw new DSSException(e);
}
} else {
return super.get(urlString);
}
}