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


Java Utils类代码示例

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


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

示例1: downloadSignedFile

import eu.europa.esig.dss.utils.Utils; //导入依赖的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: extend

import eu.europa.esig.dss.utils.Utils; //导入依赖的package包/类
@RequestMapping(method = RequestMethod.POST)
public String extend(HttpServletRequest request, HttpServletResponse response, @ModelAttribute("extensionForm") @Valid ExtensionForm extensionForm,
		BindingResult result) {
	if (result.hasErrors()) {
		return EXTENSION_TILE;
	}

	DSSDocument extendedDocument = signingService.extend(extensionForm);

	response.setContentType(extendedDocument.getMimeType().getMimeTypeString());
	response.setHeader("Content-Disposition", "attachment; filename=\"" + extendedDocument.getName() + "\"");
	try {
		Utils.copy(extendedDocument.openStream(), response.getOutputStream());
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
	}

	return null;
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:20,代码来源:ExtensionController.java

示例3: save

import eu.europa.esig.dss.utils.Utils; //导入依赖的package包/类
private void save(DSSDocument signedDocument) {
	FileChooser fileChooser = new FileChooser();
	fileChooser.setInitialFileName(signedDocument.getName());
	MimeType mimeType = signedDocument.getMimeType();
	ExtensionFilter extFilter = new ExtensionFilter(mimeType.getMimeTypeString(), "*." + MimeType.getExtension(mimeType));
	fileChooser.getExtensionFilters().add(extFilter);
	File fileToSave = fileChooser.showSaveDialog(stage);

	if (fileToSave != null) {
		try {
			FileOutputStream fos = new FileOutputStream(fileToSave);
			Utils.copy(signedDocument.openStream(), fos);
			Utils.closeQuietly(fos);
		} catch (Exception e) {
			Alert alert = new Alert(AlertType.ERROR, "Unable to save file : " + e.getMessage(), ButtonType.CLOSE);
			alert.showAndWait();
			return;
		}
	}
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:21,代码来源:SignatureController.java

示例4: getByCountry

import eu.europa.esig.dss.utils.Utils; //导入依赖的package包/类
@RequestMapping(value = "/{country:[a-z][a-z]}", method = RequestMethod.GET)
public String getByCountry(@PathVariable String country, Model model) {
	String countryUppercase = Utils.upperCase(country);
	model.addAttribute("country", countryUppercase);
	model.addAttribute("countries", tslRepository.getAllMapTSLValidationModels().keySet());
	model.addAttribute("model", tslRepository.getByCountry(countryUppercase));
	return "tsl-info-country";
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:9,代码来源:TrustedListController.java

示例5: fillParameters

import eu.europa.esig.dss.utils.Utils; //导入依赖的package包/类
private void fillParameters(AbstractSignatureParameters parameters, AbstractSignatureForm form) {
	parameters.setSignatureLevel(form.getSignatureLevel());
	parameters.setDigestAlgorithm(form.getDigestAlgorithm());
	// parameters.setEncryptionAlgorithm(form.getEncryptionAlgorithm()); retrieved from certificate
	parameters.bLevel().setSigningDate(form.getSigningDate());

	parameters.setSignWithExpiredCertificate(form.isSignWithExpiredCertificate());

	CertificateToken signingCertificate = DSSUtils.loadCertificateFromBase64EncodedString(form.getBase64Certificate());
	parameters.setSigningCertificate(signingCertificate);
	parameters.setEncryptionAlgorithm(signingCertificate.getEncryptionAlgorithm());

	List<String> base64CertificateChain = form.getBase64CertificateChain();
	if (Utils.isCollectionNotEmpty(base64CertificateChain)) {
		List<CertificateToken> certificateChain = new LinkedList<CertificateToken>();
		for (String base64Certificate : base64CertificateChain) {
			certificateChain.add(DSSUtils.loadCertificateFromBase64EncodedString(base64Certificate));
		}
		parameters.setCertificateChain(certificateChain);
	}
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:22,代码来源:SigningService.java

示例6: init

import eu.europa.esig.dss.utils.Utils; //导入依赖的package包/类
@PostConstruct
public void init() throws Exception {

	FopFactoryBuilder builder = new FopFactoryBuilder(new File(".").toURI());
	builder.setAccessibility(true);

	fopFactory = builder.build();

	foUserAgent = fopFactory.newFOUserAgent();
	foUserAgent.setCreator("DSS Webapp");
	foUserAgent.setAccessibility(true);

	TransformerFactory transformerFactory = DomUtils.getSecureTransformerFactory();

	InputStream simpleIS = FOPService.class.getResourceAsStream("/xslt/pdf/simple-report.xslt");
	templateSimpleReport = transformerFactory.newTemplates(new StreamSource(simpleIS));
	Utils.closeQuietly(simpleIS);

	InputStream detailedIS = FOPService.class.getResourceAsStream("/xslt/pdf/detailed-report.xslt");
	templateDetailedReport = transformerFactory.newTemplates(new StreamSource(detailedIS));
	Utils.closeQuietly(detailedIS);
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:23,代码来源:FOPService.java

示例7: testRemoteSignature

import eu.europa.esig.dss.utils.Utils; //导入依赖的package包/类
@Test
public void testRemoteSignature() throws Exception {
	List<RemoteKeyEntry> keys = getRemoteToken().getKeys();
	assertTrue(Utils.isCollectionNotEmpty(keys));

	String alias = keys.get(0).getAlias();

	ToBeSigned toBeSigned = new ToBeSigned(DSSUtils.digest(DigestAlgorithm.SHA256, "Hello world!".getBytes(Charset.defaultCharset())));
	SignatureValue signatureValue = getRemoteToken().sign(toBeSigned, DigestAlgorithm.SHA256, alias);
	assertNotNull(signatureValue);
	assertNotNull(signatureValue.getAlgorithm());
	assertNotNull(signatureValue.getValue());

	SignatureValue signatureValue2 = getRemoteToken().sign(toBeSigned, DigestAlgorithm.SHA256, alias);
	SignatureValue signatureValue3 = getRemoteToken().sign(toBeSigned, DigestAlgorithm.SHA256, alias);
	assertEquals(signatureValue2.getAlgorithm(), signatureValue3.getAlgorithm());
	assertEquals(Utils.toBase64(signatureValue2.getValue()), Utils.toBase64(signatureValue3.getValue()));

	RemoteKeyEntry key = getRemoteToken().getKey(alias);
	assertNotNull(key);
	assertNotNull(key.getCertificate());
	assertEquals(alias, key.getAlias());

	RemoteKeyEntry key2 = getRemoteToken().getKey("bla");
	assertNull(key2);
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:27,代码来源:AbstractServerSigning.java

示例8: 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");
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:40,代码来源:SignatureRestServiceIT.java

示例9: generateSimpleReport

import eu.europa.esig.dss.utils.Utils; //导入依赖的package包/类
@Test
public void generateSimpleReport() throws Exception {
	JAXBContext context = JAXBContext.newInstance(SimpleReport.class.getPackage().getName());
	Unmarshaller unmarshaller = context.createUnmarshaller();
	Marshaller marshaller = context.createMarshaller();

	SimpleReport simpleReport = (SimpleReport) unmarshaller.unmarshal(new File("src/test/resources/simpleReport.xml"));
	assertNotNull(simpleReport);

	StringWriter writer = new StringWriter();
	marshaller.marshal(simpleReport, writer);

	String htmlSimpleReport = service.generateSimpleReport(writer.toString());
	assertTrue(Utils.isStringNotEmpty(htmlSimpleReport));
	logger.debug("Simple report html : " + htmlSimpleReport);
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:17,代码来源:XSLTServiceTest.java

示例10: generateSimpleReportMulti

import eu.europa.esig.dss.utils.Utils; //导入依赖的package包/类
@Test
public void generateSimpleReportMulti() throws Exception {
	JAXBContext context = JAXBContext.newInstance(SimpleReport.class.getPackage().getName());
	Unmarshaller unmarshaller = context.createUnmarshaller();
	Marshaller marshaller = context.createMarshaller();

	SimpleReport simpleReport = (SimpleReport) unmarshaller.unmarshal(new File("src/test/resources/simple-report-multi-signatures.xml"));
	assertNotNull(simpleReport);

	StringWriter writer = new StringWriter();
	marshaller.marshal(simpleReport, writer);

	String htmlSimpleReport = service.generateSimpleReport(writer.toString());
	assertTrue(Utils.isStringNotEmpty(htmlSimpleReport));
	logger.debug("Simple report html : " + htmlSimpleReport);
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:17,代码来源:XSLTServiceTest.java

示例11: generateDetailedReport

import eu.europa.esig.dss.utils.Utils; //导入依赖的package包/类
@Test
public void generateDetailedReport() throws Exception {
	JAXBContext context = JAXBContext.newInstance(DetailedReport.class.getPackage().getName());
	Unmarshaller unmarshaller = context.createUnmarshaller();
	Marshaller marshaller = context.createMarshaller();

	DetailedReport detailedReport = (DetailedReport) unmarshaller.unmarshal(new File("src/test/resources/detailedReport.xml"));
	assertNotNull(detailedReport);

	StringWriter writer = new StringWriter();
	marshaller.marshal(detailedReport, writer);

	String htmlDetailedReport = service.generateDetailedReport(writer.toString());
	assertTrue(Utils.isStringNotEmpty(htmlDetailedReport));
	logger.debug("Detailed report html : " + htmlDetailedReport);
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:17,代码来源:XSLTServiceTest.java

示例12: generateDetailedReportMultiSignatures

import eu.europa.esig.dss.utils.Utils; //导入依赖的package包/类
@Test
public void generateDetailedReportMultiSignatures() throws Exception {
	JAXBContext context = JAXBContext.newInstance(DetailedReport.class.getPackage().getName());
	Unmarshaller unmarshaller = context.createUnmarshaller();
	Marshaller marshaller = context.createMarshaller();

	DetailedReport detailedReport = (DetailedReport) unmarshaller.unmarshal(new File("src/test/resources/detailed-report-multi-signatures.xml"));
	assertNotNull(detailedReport);

	StringWriter writer = new StringWriter();
	marshaller.marshal(detailedReport, writer);

	String htmlDetailedReport = service.generateDetailedReport(writer.toString());
	assertTrue(Utils.isStringNotEmpty(htmlDetailedReport));
	logger.debug("Detailed report html : " + htmlDetailedReport);
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:17,代码来源:XSLTServiceTest.java

示例13: 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;
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:25,代码来源:SigningTask.java

示例14: buildParameters

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

示例15: getSigner

import eu.europa.esig.dss.utils.Utils; //导入依赖的package包/类
private DSSPrivateKeyEntry getSigner(List<DSSPrivateKeyEntry> keys) throws Exception {
	DSSPrivateKeyEntry selectedKey = null;
	if (Utils.isCollectionEmpty(keys)) {
		throwException("No certificate found", null);
	} else if (Utils.collectionSize(keys) == 1) {
		selectedKey = keys.get(0);
	} else {
		FutureTask<DSSPrivateKeyEntry> future = new FutureTask<DSSPrivateKeyEntry>(new SelectCertificateTask(keys));
		Platform.runLater(future);
		selectedKey = future.get();
		if (selectedKey == null) {
			throwException("No selected certificate", null);
		}
	}
	return selectedKey;
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:17,代码来源:SigningTask.java


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