本文整理匯總了Java中javax.xml.crypto.MarshalException類的典型用法代碼示例。如果您正苦於以下問題:Java MarshalException類的具體用法?Java MarshalException怎麽用?Java MarshalException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MarshalException類屬於javax.xml.crypto包,在下文中一共展示了MarshalException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: signRequest
import javax.xml.crypto.MarshalException; //導入依賴的package包/類
@Test
public void signRequest() throws JAXBException, ParserConfigurationException, CertificateException, KeyException, MarshalException, NoSuchAlgorithmException, SOAPException, XPathExpressionException, XMLSignatureException, InvalidAlgorithmParameterException, java.security.cert.CertificateException, NoSuchProviderException, KeyStoreException, IOException, UnrecoverableKeyException {
Serializable payload = createRequest();
SOAPMessage signedRequest = sign(
marshall(
payload,
getMarshaller(payload.getClass())
),
getClient()
);
System.out.println("============ SIGNED SOAP MESSAGE ================");
signedRequest.writeTo(System.out);
System.out.println("\n=================================================");
}
示例2: marshal
import javax.xml.crypto.MarshalException; //導入依賴的package包/類
/**
* This method invokes the {@link #marshalParams marshalParams}
* method to marshal any algorithm-specific parameters.
*/
public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
throws MarshalException
{
Document ownerDoc = DOMUtils.getOwnerDocument(parent);
Element smElem = DOMUtils.createElement(ownerDoc, "SignatureMethod",
XMLSignature.XMLNS, dsPrefix);
DOMUtils.setAttribute(smElem, "Algorithm", getAlgorithm());
if (getParameterSpec() != null) {
marshalParams(smElem, dsPrefix);
}
parent.appendChild(smElem);
}
示例3: assinaDoc
import javax.xml.crypto.MarshalException; //導入依賴的package包/類
/**
* Assinatura do XML de Envio de Lote da CT-e utilizando Certificado
* Digital.
*
* @param Conteudo do Xml
* @param Nome do Certificado Digital
* @return String do XMl Assinado
* @throws Exception
*/
private static String assinaDoc(String xml, String tipo) throws CteException {
try {
Document document = documentFactory(xml);
XMLSignatureFactory signatureFactory = XMLSignatureFactory.getInstance("DOM");
ArrayList<Transform> transformList = signatureFactory(signatureFactory);
loadCertificates(signatureFactory);
if (tipo.equals(EVENTO)) {
assinar(tipo, signatureFactory, transformList, privateKey, keyInfo, document, 0);
} else {
for (int i = 0; i < document.getDocumentElement().getElementsByTagName(tipo).getLength(); i++) {
assinar(tipo, signatureFactory, transformList, privateKey, keyInfo, document, i);
}
}
return outputXML(document);
} catch (SAXException | IOException | ParserConfigurationException | NoSuchAlgorithmException | InvalidAlgorithmParameterException | KeyStoreException | UnrecoverableEntryException | NoSuchProviderException | CertificateException | MarshalException | XMLSignatureException | CertificadoException e) {
throw new CteException("Erro ao Assinar Cte" + e.getMessage());
}
}
示例4: marshalPGPData
import javax.xml.crypto.MarshalException; //導入依賴的package包/類
/**
* Marshals a {@link PGPData}
*
* @param xwriter
* @param pgpData
* @param dsPrefix
* @param context
* @throws MarshalException
*/
public static void marshalPGPData(XmlWriter xwriter, PGPData pgpData, String dsPrefix, XMLCryptoContext context)
throws MarshalException {
xwriter.writeStartElement(dsPrefix, "PGPData", XMLSignature.XMLNS);
// create and append PGPKeyID element
byte[] keyId = pgpData.getKeyId();
if (keyId != null) {
xwriter.writeTextElement(dsPrefix, "PGPKeyID", XMLSignature.XMLNS, Base64.encode(keyId));
}
// create and append PGPKeyPacket element
byte[] keyPacket = pgpData.getKeyPacket();
if (keyPacket != null) {
xwriter.writeTextElement(dsPrefix, "XMLSignature.XMLNS", XMLSignature.XMLNS, Base64.encode(keyPacket));
}
// create and append any elements
@SuppressWarnings("unchecked")
List<XMLStructure> externalElements = pgpData.getExternalElements();
for (XMLStructure externalItem : externalElements) {
xwriter.marshalStructure(externalItem, dsPrefix, context);
}
xwriter.writeEndElement(); // "PGPData"
}
示例5: marshal
import javax.xml.crypto.MarshalException; //導入依賴的package包/類
@Override
public void marshal(XmlWriter xwriter, String dsPrefix, XMLCryptoContext context)
throws MarshalException
{
xwriter.writeStartElement(dsPrefix, "RetrievalMethod", XMLSignature.XMLNS);
// TODO - see whether it is important to capture the "here" attribute as part of the
// marshalling - do any of the tests fail?
// add URI and Type attributes
here = xwriter.writeAttribute("", "", "URI", uri);
xwriter.writeAttribute("", "", "Type", type);
// add Transforms elements
if (!transforms.isEmpty()) {
xwriter.writeStartElement(dsPrefix, "Transforms", XMLSignature.XMLNS);
for (Transform transform : transforms) {
((DOMTransform)transform).marshal(xwriter, dsPrefix, context);
}
xwriter.writeEndElement(); // "Transforms"
}
xwriter.writeEndElement(); // "RetrievalMethod"
}
示例6: marshalInternal
import javax.xml.crypto.MarshalException; //導入依賴的package包/類
private static void marshalInternal(XmlWriter xwriter, KeyInfo ki,
String dsPrefix, XMLCryptoContext context, boolean declareNamespace) throws MarshalException {
xwriter.writeStartElement(dsPrefix, "KeyInfo", XMLSignature.XMLNS);
if (declareNamespace) {
xwriter.writeNamespace(dsPrefix, XMLSignature.XMLNS);
}
xwriter.writeIdAttribute("", "", "Id", ki.getId());
// create and append KeyInfoType elements
List<XMLStructure> keyInfoTypes = getContent(ki);
for (XMLStructure kiType : keyInfoTypes) {
xwriter.marshalStructure(kiType, dsPrefix, context);
}
xwriter.writeEndElement(); // "KeyInfo"
}
示例7: testReferenceCount
import javax.xml.crypto.MarshalException; //導入依賴的package包/類
@org.junit.Test
public void testReferenceCount() throws Exception {
Element signedInfoElement =
getSignedInfoElement("src/test/resources/interop/c14n/Y4", "signature-manifest.xml");
InternalDOMCryptoContext context = new InternalDOMCryptoContext();
new DOMSignedInfo(signedInfoElement, context, null);
context.setProperty("org.apache.jcp.xml.dsig.secureValidation", Boolean.TRUE);
try {
new DOMSignedInfo(signedInfoElement, context, null);
} catch (MarshalException ex) {
String error =
"A maxiumum of 30 references per Manifest are allowed with secure validation";
assertTrue(ex.getMessage().contains(error));
}
}
示例8: assinaDocNFe
import javax.xml.crypto.MarshalException; //導入依賴的package包/類
/**
* Assinatura do XML de Envio de Lote da NF-e utilizando Certificado
* Digital.
*
* @param Conteudo do Xml
* @param Nome do Certificado Digital
* @return String do XMl Assinado
* @throws Exception
*/
private static String assinaDocNFe(String xml, String tipo) throws NfeException{
Document document = null;
try {
document = documentFactory(xml);
XMLSignatureFactory signatureFactory = XMLSignatureFactory.getInstance("DOM");
ArrayList<Transform> transformList = signatureFactory(signatureFactory);
loadCertificates(signatureFactory);
for (int i = 0; i < document.getDocumentElement().getElementsByTagName(tipo).getLength(); i++) {
assinarNFe(tipo, signatureFactory, transformList, privateKey, keyInfo, document, i);
}
} catch (SAXException | IOException | ParserConfigurationException | NoSuchAlgorithmException | InvalidAlgorithmParameterException | KeyStoreException | UnrecoverableEntryException | NoSuchProviderException | CertificateException | CertificadoException | MarshalException | XMLSignatureException e) {
throw new NfeException("Erro ao Assinar Nfe"+e.getMessage());
}
return outputXML(document);
}
示例9: marshalParams
import javax.xml.crypto.MarshalException; //導入依賴的package包/類
@Override
public void marshalParams(XMLStructure parent, XMLCryptoContext context) throws MarshalException {
LOG.debug("marshallParams(parent,context)");
DOMStructure domParent = (DOMStructure) parent;
Node parentNode = domParent.getNode();
Element parentElement = (Element) parentNode;
parentElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:mdssi",
"http://schemas.openxmlformats.org/package/2006/digital-signature");
Document document = parentNode.getOwnerDocument();
for (String sourceId : this.sourceIds) {
Element relationshipReferenceElement = document.createElementNS(
"http://schemas.openxmlformats.org/package/2006/digital-signature", "mdssi:RelationshipReference");
relationshipReferenceElement.setAttribute("SourceId", sourceId);
parentElement.appendChild(relationshipReferenceElement);
}
for (String sourceType : this.sourceTypes) {
Element relationshipsGroupReferenceElement = document.createElementNS(
"http://schemas.openxmlformats.org/package/2006/digital-signature",
"mdssi:RelationshipsGroupReference");
relationshipsGroupReferenceElement.setAttribute("SourceType", sourceType);
parentElement.appendChild(relationshipsGroupReferenceElement);
}
}
示例10: verifySignature
import javax.xml.crypto.MarshalException; //導入依賴的package包/類
/**
* Verification via the default JSR105 implementation triggers some
* canonicalization errors.
*
* @param odfUrl
* @param signatureNode
* @throws MarshalException
* @throws XMLSignatureException
*/
private boolean verifySignature(URL odfUrl, Node signatureNode) throws MarshalException, XMLSignatureException {
// work-around for Java 7
Element signedPropertiesElement = (Element) ((Element) signatureNode)
.getElementsByTagNameNS(XAdESXLSignatureFacet.XADES_NAMESPACE, "SignedProperties").item(0);
if (null != signedPropertiesElement) {
signedPropertiesElement.setIdAttribute("Id", true);
}
DOMValidateContext domValidateContext = new DOMValidateContext(new KeyInfoKeySelector(), signatureNode);
ODFURIDereferencer dereferencer = new ODFURIDereferencer(odfUrl);
domValidateContext.setURIDereferencer(dereferencer);
XMLSignatureFactory xmlSignatureFactory = XMLSignatureFactory.getInstance();
LOG.debug("java version: " + System.getProperty("java.version"));
/*
* Requires Java 6u10 because of a bug. See also:
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6696582
*/
XMLSignature xmlSignature = xmlSignatureFactory.unmarshalXMLSignature(domValidateContext);
boolean validity = xmlSignature.validate(domValidateContext);
return validity;
}
示例11: buildFault
import javax.xml.crypto.MarshalException; //導入依賴的package包/類
public Envelope buildFault(String request) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, MarshalException, XMLSignatureException {
Envelope r = buildResponse(request, false);
r.getBody().getUnknownXMLObjects().clear();
Fault fault = SAMLUtil.buildXMLObject(Fault.class);
Detail detail = SAMLUtil.buildXMLObject(Detail.class);
FaultString msg = SAMLUtil.buildXMLObject(FaultString.class);
msg.setValue("test");
fault.setMessage(msg);
fault.setDetail(detail);
XSAny d = new XSAnyBuilder().buildObject("urn:test", "fault", "fa");
detail.getUnknownXMLObjects().add(d);
r.getBody().getUnknownXMLObjects().add(fault);
return r;
}
示例12: sign
import javax.xml.crypto.MarshalException; //導入依賴的package包/類
public synchronized void sign()
throws MarshalException,
XMLSignatureException,
KeyException {
if (this.document == null)
throw new RuntimeException("Can't sign a NULL document");
Reference reference = this.signatureFactory.newReference(
referenceUri,
this.digestMethod,
this.transformList,
null,
null);
SignedInfo signedInfo = this.signatureFactory.newSignedInfo(
this.canonicalizationMethod,
this.signatureMethod,
Collections.singletonList(reference));
// Create the KeyInfo containing the X509Data.
X509Data xd = this.keyInfoFactory.newX509Data(
Collections.singletonList(this.certificateWithKey.certificate));
KeyInfo keyInfo = this.keyInfoFactory.newKeyInfo(Collections.singletonList(xd));
XMLSignature signature = this.signatureFactory.newXMLSignature(
signedInfo,
keyInfo);
DOMSignContext signingContext = new DOMSignContext(
this.certificateWithKey.privateKey,
document.getDocumentElement());
signature.sign(signingContext);
}
示例13: validate
import javax.xml.crypto.MarshalException; //導入依賴的package包/類
public synchronized boolean validate()
throws MarshalException,
XMLSignatureException {
// Find Signature element.
NodeList list = document.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
if (list.getLength() == 0) {
throw new RuntimeException("Cannot find Signature element");
}
// Create a DOMValidateContext and specify a KeySelector
// and document context.
DOMValidateContext validateContext = new DOMValidateContext(new X509CertificateKeySelector(), list.item(0));
// Unmarshal the XMLSignature.
XMLSignature signature = this.signatureFactory.unmarshalXMLSignature(validateContext);
// Validate the XMLSignature.
if (signature.validate(validateContext)) {
return true;
} else {
Iterator<?> i = signature.getSignedInfo().getReferences().iterator();
for (int j = 0; i.hasNext(); j++) {
System.out.print("ref[" + j + "] -> ");
Reference ref = (Reference) i.next();
System.out.print(ref.getURI());
System.out.print(", ");
System.out.print(ref.getDigestMethod().toString());
System.out.print(", ");
System.out.print(ref.getId());
boolean refValid = ref.validate(validateContext);
System.out.print(", validity status: " + refValid + "\r\n");
}
return false;
}
}
示例14: sign
import javax.xml.crypto.MarshalException; //導入依賴的package包/類
public Document sign(FileInputStream fileStream, KeyPair keyPair)
throws ParserConfigurationException, SAXException, IOException,
NoSuchAlgorithmException, InvalidAlgorithmParameterException,
KeyException, MarshalException, XMLSignatureException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(fileStream);
DOMSignContext signContext = new DOMSignContext(keyPair.getPrivate(),
document.getDocumentElement());
XMLSignatureFactory signFactory = XMLSignatureFactory
.getInstance("DOM");
Reference ref = signFactory.newReference("", signFactory
.newDigestMethod(digestMethod, null), Collections
.singletonList(signFactory.newTransform(Transform.ENVELOPED,
(TransformParameterSpec) null)), null, null);
SignedInfo si = signFactory.newSignedInfo(signFactory
.newCanonicalizationMethod(
CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS,
(C14NMethodParameterSpec) null), signFactory
.newSignatureMethod(signatureMethod, null), Collections
.singletonList(ref));
KeyInfoFactory kif = signFactory.getKeyInfoFactory();
KeyValue kv = kif.newKeyValue(keyPair.getPublic());
KeyInfo ki = kif.newKeyInfo(Collections.singletonList(kv));
XMLSignature signature = signFactory.newXMLSignature(si, ki);
signature.sign(signContext);
return document;
}
示例15: validate
import javax.xml.crypto.MarshalException; //導入依賴的package包/類
private boolean validate(final DOMValidateContext validationContext)
throws DigitalSignatureValidationException {
try {
// if (getLogger().isDebugLoggingEnabled()) {
// enableReferenceCaching(validationContext);
// }
XMLSignatureFactory factory = XMLSignatureFactory
.getInstance(XML_MECHANISM_TYPE);
XMLSignature signature = factory
.unmarshalXMLSignature(validationContext);
boolean validationResult = signature.validate(validationContext);
validationResult = workaroundOpenamBug(signature,
validationContext, validationResult);
// if (getLogger().isDebugLoggingEnabled()) {
// debugLogReferences(signature, validationContext);
// }
return validationResult;
} catch (XMLSignatureException | MarshalException exception) {
throw new DigitalSignatureValidationException(
"Error occurred during digital signature validation process",
DigitalSignatureValidationException.ReasonEnum.EXCEPTION_OCCURRED,
exception);
}
}