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


Java InMemoryDocument类代码示例

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


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

示例1: downloadSignedFile

import eu.europa.esig.dss.InMemoryDocument; //导入依赖的package包/类
@RequestMapping(value = "/download", method = RequestMethod.GET)
public String downloadSignedFile(@ModelAttribute("signedDocument") InMemoryDocument signedDocument, HttpServletResponse response) {
	try {
		MimeType mimeType = signedDocument.getMimeType();
		if (mimeType != null) {
			response.setContentType(mimeType.getMimeTypeString());
		}
		response.setHeader("Content-Transfer-Encoding", "binary");
		response.setHeader("Content-Disposition", "attachment; filename=\"" + signedDocument.getName() + "\"");
		Utils.copy(new ByteArrayInputStream(signedDocument.getBytes()), response.getOutputStream());

	} catch (Exception e) {
		logger.error("An error occured while pushing file in response : " + e.getMessage(), e);
	}
	return null;
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:17,代码来源:SignatureController.java

示例2: testSigningAndExtensionMultiDocuments

import eu.europa.esig.dss.InMemoryDocument; //导入依赖的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");
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:40,代码来源:SignatureRestServiceIT.java

示例3: transformReference

import eu.europa.esig.dss.InMemoryDocument; //导入依赖的package包/类
/**
 * Preconditions:
 * - The reference data is XML
 * - The last transformation is canonicalization.
 *
 * @param reference
 *            {@code DSSReference} to be transformed
 * @return {@code DSSDocument} containing transformed reference's data
 */
@Override
protected DSSDocument transformReference(final DSSReference reference) {

	DSSDocument dssDocument = reference.getContents();
	final List<DSSTransform> transforms = reference.getTransforms();
	if (Utils.isCollectionEmpty(transforms)) {
		return dssDocument;
	}

	// In the case of ENVELOPED signature the document to sign is an XML. However one of the references can point to
	// another document this test case is not taken into account!

	Node nodeToTransform = null;
	final String uri = reference.getUri();
	// Check if the reference is related to the whole document
	if (Utils.isStringNotBlank(uri) && uri.startsWith("#") && !isXPointer(uri)) {

		final Document document = DomUtils.buildDOM(dssDocument);
		DSSXMLUtils.recursiveIdBrowse(document.getDocumentElement());
		final String uri_id = uri.substring(1);
		nodeToTransform = document.getElementById(uri_id);
	}
	byte[] transformedReferenceBytes = applyTransformations(dssDocument, transforms, nodeToTransform);
	return new InMemoryDocument(transformedReferenceBytes);
}
 
开发者ID:esig,项目名称:dss,代码行数:35,代码来源:EnvelopedSignatureBuilder.java

示例4: signDocument

import eu.europa.esig.dss.InMemoryDocument; //导入依赖的package包/类
/**
 * Adds signature value to the signature and returns XML signature (InMemoryDocument)
 *
 * @param signatureValue
 * @return
 * @throws DSSException
 */
@Override
public DSSDocument signDocument(final byte[] signatureValue) throws DSSException {
	if (!built) {
		build();
	}

	final EncryptionAlgorithm encryptionAlgorithm = params.getEncryptionAlgorithm();
	final byte[] signatureValueBytes = DSSSignatureUtils.convertToXmlDSig(encryptionAlgorithm, signatureValue);
	final String signatureValueBase64Encoded = Utils.toBase64(signatureValueBytes);
	final Text signatureValueNode = documentDom.createTextNode(signatureValueBase64Encoded);
	signatureValueDom.appendChild(signatureValueNode);

	byte[] documentBytes = DSSXMLUtils.serializeNode(documentDom);
	final InMemoryDocument inMemoryDocument = new InMemoryDocument(documentBytes);
	inMemoryDocument.setMimeType(MimeType.XML);
	return inMemoryDocument;
}
 
开发者ID:esig,项目名称:dss,代码行数:25,代码来源:XAdESSignatureBuilder.java

示例5: init

import eu.europa.esig.dss.InMemoryDocument; //导入依赖的package包/类
@Before
public void init() throws Exception {
	documentToSign = new InMemoryDocument("Hello World !".getBytes(), "test.text");

	signatureParameters = new ASiCWithXAdESSignatureParameters();
	signatureParameters.bLevel().setSigningDate(new Date());
	signatureParameters.setSigningCertificate(getSigningCert());
	signatureParameters.setCertificateChain(getCertificateChain());
	signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B);
	signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_E);
	Policy policy = new Policy();
	policy.setId("urn:oid:1.3.6.1.4.1.10015.1000.3.2.1");
	policy.setQualifier("OIDAsURN");
	policy.setDigestAlgorithm(DigestAlgorithm.SHA1);
	policy.setDigestValue(Utils.fromBase64("gIHiaetEE94gbkCRygQ9WspxUdw="));
	policy.setSpuri("https://www.sk.ee/repository/bdoc-spec21.pdf");
	signatureParameters.bLevel().setSignaturePolicy(policy);

	service = new ASiCWithXAdESService(getCompleteCertificateVerifier());
}
 
开发者ID:esig,项目名称:dss,代码行数:21,代码来源:ASiCEXAdESLevelBPolicyIdTest.java

示例6: getOriginalDocuments

import eu.europa.esig.dss.InMemoryDocument; //导入依赖的package包/类
@Override
public List<DSSDocument> getOriginalDocuments(final String signatureId) throws DSSException {
	if (Utils.isStringBlank(signatureId)) {
		throw new NullPointerException("signatureId");
	}
	List<DSSDocument> results = new ArrayList<DSSDocument>();

	for (final Object signerInformationObject : cmsSignedData.getSignerInfos().getSigners()) {

		final SignerInformation signerInformation = (SignerInformation) signerInformationObject;
		final CAdESSignature cadesSignature = new CAdESSignature(cmsSignedData, signerInformation, validationCertPool);
		cadesSignature.setSignatureFilename(document.getName());
		cadesSignature.setDetachedContents(detachedContents);
		cadesSignature.setProvidedSigningCertificateToken(providedSigningCertificateToken);
		if (Utils.areStringsEqual(cadesSignature.getId(), signatureId)) {
			results.add(new InMemoryDocument(cadesSignature.getOriginalDocumentStream()));
		}
	}
	return results;
}
 
开发者ID:esig,项目名称:dss,代码行数:21,代码来源:CMSDocumentValidator.java

示例7: getCurrentDocument

import eu.europa.esig.dss.InMemoryDocument; //导入依赖的package包/类
private DSSDocument getCurrentDocument(String filepath, ZipInputStream zis) throws IOException {
	try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
		Utils.copy(zis, baos);
		baos.flush();
		return new InMemoryDocument(baos.toByteArray(), filepath);
	}
}
 
开发者ID:esig,项目名称:dss,代码行数:8,代码来源:AbstractASiCContainerExtractor.java

示例8: getOriginalDocumentFromDetachedSignature

import eu.europa.esig.dss.InMemoryDocument; //导入依赖的package包/类
@Test(expected = DSSException.class)
public final void getOriginalDocumentFromDetachedSignature() 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.DETACHED);
	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();

	validator.getOriginalDocuments(reports.getDiagnosticData().getFirstSignatureId());
}
 
开发者ID:esig,项目名称:dss,代码行数:24,代码来源:GetOriginalDocumentTest.java

示例9: getSignedDocument

import eu.europa.esig.dss.InMemoryDocument; //导入依赖的package包/类
@Override
protected DSSDocument getSignedDocument() throws Exception {
	DSSDocument documentToSign = new InMemoryDocument("Hello world".getBytes());

	CAdESSignatureParameters signatureParameters = new CAdESSignatureParameters();
	signatureParameters.setSigningCertificate(getSigningCert());
	signatureParameters.setCertificateChain(getCertificateChain());
	signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING);
	signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_LT);

	CAdESService service = new CAdESService(getCompleteCertificateVerifier());
	service.setTspSource(getGoodTsa());

	ToBeSigned dataToSign = service.getDataToSign(documentToSign, signatureParameters);
	SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry());
	return service.signDocument(documentToSign, signatureParameters, signatureValue);
}
 
开发者ID:esig,项目名称:dss,代码行数:18,代码来源:CAdESBaselineTTest.java

示例10: getSignedDocument

import eu.europa.esig.dss.InMemoryDocument; //导入依赖的package包/类
@Override
protected DSSDocument getSignedDocument() throws Exception {
	DSSDocument documentToSign = new InMemoryDocument("Hello world".getBytes());

	CAdESSignatureParameters signatureParameters = new CAdESSignatureParameters();
	signatureParameters.setSigningCertificate(getSigningCert());
	signatureParameters.setCertificateChain(getCertificateChain());
	signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING);
	signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_T);

	CAdESService service = new CAdESService(getCompleteCertificateVerifier());
	service.setTspSource(getGoodTsa());

	ToBeSigned dataToSign = service.getDataToSign(documentToSign, signatureParameters);
	SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry());
	return service.signDocument(documentToSign, signatureParameters, signatureValue);
}
 
开发者ID:esig,项目名称:dss,代码行数:18,代码来源:CAdESBaselineLTATest.java

示例11: getSignedDocument

import eu.europa.esig.dss.InMemoryDocument; //导入依赖的package包/类
@Override
protected DSSDocument getSignedDocument() throws Exception {
	DSSDocument documentToSign = new InMemoryDocument("Hello world".getBytes());

	CAdESSignatureParameters signatureParameters = new CAdESSignatureParameters();
	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(documentToSign, signatureParameters);
	SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry());
	return service.signDocument(documentToSign, signatureParameters, signatureValue);
}
 
开发者ID:esig,项目名称:dss,代码行数:17,代码来源:CAdESBaselineBTest.java

示例12: init

import eu.europa.esig.dss.InMemoryDocument; //导入依赖的package包/类
@Before
public void init() throws Exception {
	documentToSign = new InMemoryDocument("Hello World".getBytes());

	OnlineTSPSource tspSource = getGoodTsa();
	TimeStampToken timeStampResponse = tspSource.getTimeStampResponse(DigestAlgorithm.SHA256,
			DSSUtils.digest(DigestAlgorithm.SHA256, DSSUtils.toByteArray(documentToSign)));
	TimestampToken contentTimestamp = new TimestampToken(timeStampResponse, TimestampType.CONTENT_TIMESTAMP, new CertificatePool());

	signatureParameters = new CAdESSignatureParameters();
	signatureParameters.bLevel().setSigningDate(new Date());
	signatureParameters.setSigningCertificate(getSigningCert());
	signatureParameters.setCertificateChain(getCertificateChain());
	signatureParameters.setSignaturePackaging(SignaturePackaging.DETACHED);
	signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B);
	signatureParameters.setContentTimestamps(Arrays.asList(contentTimestamp));

	service = new CAdESService(getCompleteCertificateVerifier());
}
 
开发者ID:esig,项目名称:dss,代码行数:20,代码来源:CAdESLevelBDetachedWithContentTimestampTest.java

示例13: getValidationReport

import eu.europa.esig.dss.InMemoryDocument; //导入依赖的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();
}
 
开发者ID:esig,项目名称:dss,代码行数:23,代码来源:CAdESLevelBDetachedDigestDocumentTest.java

示例14: init

import eu.europa.esig.dss.InMemoryDocument; //导入依赖的package包/类
@Before
public void init() throws Exception {
	documentToSign = new InMemoryDocument("Hello World".getBytes());

	OnlineTSPSource tspSource = getGoodTsa();

	TimeStampToken timeStampResponse1 = tspSource.getTimeStampResponse(DigestAlgorithm.SHA256,
			DSSUtils.digest(DigestAlgorithm.SHA256, DSSUtils.toByteArray(documentToSign)));
	TimestampToken contentTimestamp1 = new TimestampToken(timeStampResponse1, TimestampType.CONTENT_TIMESTAMP, new CertificatePool());

	TimeStampToken timeStampResponse2 = tspSource.getTimeStampResponse(DigestAlgorithm.SHA1,
			DSSUtils.digest(DigestAlgorithm.SHA1, DSSUtils.toByteArray(documentToSign)));
	TimestampToken contentTimestamp2 = new TimestampToken(timeStampResponse2, TimestampType.CONTENT_TIMESTAMP, new CertificatePool());

	signatureParameters = new CAdESSignatureParameters();
	signatureParameters.bLevel().setSigningDate(new Date());
	signatureParameters.setSigningCertificate(getSigningCert());
	signatureParameters.setCertificateChain(getSigningCert());
	signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING);
	signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B);
	signatureParameters.setContentTimestamps(Arrays.asList(contentTimestamp1, contentTimestamp2));

	service = new CAdESService(getCompleteCertificateVerifier());
}
 
开发者ID:esig,项目名称:dss,代码行数:25,代码来源:CAdESLevelBWithTwoContentTimestampsTest.java

示例15: createPackageZip

import eu.europa.esig.dss.InMemoryDocument; //导入依赖的package包/类
protected DSSDocument createPackageZip(List<DSSDocument> documents, Date signingDate) {
	try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(baos)) {

		for (DSSDocument document : documents) {
			final String documentName = document.getName();
			final String name = documentName != null ? documentName : ZIP_ENTRY_DETACHED_FILE;
			final ZipEntry entryDocument = new ZipEntry(name);
			entryDocument.setTime(signingDate.getTime());
			entryDocument.setMethod(ZipEntry.STORED);
			byte[] byteArray = DSSUtils.toByteArray(document);
			entryDocument.setSize(byteArray.length);
			entryDocument.setCompressedSize(byteArray.length);
			final CRC32 crc = new CRC32();
			crc.update(byteArray);
			entryDocument.setCrc(crc.getValue());
			zos.putNextEntry(entryDocument);
			Utils.write(byteArray, zos);
		}

		zos.finish();

		return new InMemoryDocument(baos.toByteArray(), "package.zip");
	} catch (IOException e) {
		throw new DSSException("Unable to create package.zip file", e);
	}
}
 
开发者ID:esig,项目名称:dss,代码行数:27,代码来源:AbstractGetDataToSignASiCS.java


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