Java Code Examples for org.apache.xml.security.transforms.Transform#performTransform()

The following examples show how to use org.apache.xml.security.transforms.Transform#performTransform() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XadesTSpecification.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private byte[] generateTimestampDigest(Element baseElement, String c14nMethodValue) {
   try {
      Node signatureValue = DomUtils.getMatchingChilds(baseElement, "http://www.w3.org/2000/09/xmldsig#", "SignatureValue").item(0);
      Transform transform = new Transform(signatureValue.getOwnerDocument(), c14nMethodValue);
      XMLSignatureInput refData = transform.performTransform(new XMLSignatureInput(signatureValue));
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      if (refData.isByteArray()) {
         baos.write(refData.getBytes());
      } else if (refData.isOctetStream()) {
         baos.write(ConnectorIOUtils.getBytes(refData.getOctetStream()));
      }

      return baos.toByteArray();
   } catch (Exception var7) {
      throw new IllegalArgumentException("Unable to calculateDigest", var7);
   }
}
 
Example 2
Source File: XadesTSpecification.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private byte[] generateTimestampDigest(Element baseElement, String c14nMethodValue) {
   try {
      Node signatureValue = DomUtils.getMatchingChilds(baseElement, "http://www.w3.org/2000/09/xmldsig#", "SignatureValue").item(0);
      Transform transform = new Transform(signatureValue.getOwnerDocument(), c14nMethodValue);
      XMLSignatureInput refData = transform.performTransform(new XMLSignatureInput(signatureValue));
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      if (refData.isByteArray()) {
         baos.write(refData.getBytes());
      } else if (refData.isOctetStream()) {
         baos.write(ConnectorIOUtils.getBytes(refData.getOctetStream()));
      }

      return baos.toByteArray();
   } catch (Exception var7) {
      throw new IllegalArgumentException("Unable to calculateDigest", var7);
   }
}
 
Example 3
Source File: XadesTSpecification.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private byte[] generateTimestampDigest(Element baseElement, String c14nMethodValue) {
   try {
      Node signatureValue = DomUtils.getMatchingChilds(baseElement, "http://www.w3.org/2000/09/xmldsig#", "SignatureValue").item(0);
      Transform transform = new Transform(signatureValue.getOwnerDocument(), c14nMethodValue);
      XMLSignatureInput refData = transform.performTransform(new XMLSignatureInput(signatureValue));
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      if (refData.isByteArray()) {
         baos.write(refData.getBytes());
      } else if (refData.isOctetStream()) {
         baos.write(ConnectorIOUtils.getBytes(refData.getOctetStream()));
      }

      return baos.toByteArray();
   } catch (Exception var7) {
      throw new IllegalArgumentException("Unable to calculateDigest", var7);
   }
}
 
Example 4
Source File: XadesTSpecification.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private byte[] generateTimestampDigest(Element baseElement, String c14nMethodValue) {
   try {
      Node signatureValue = DomUtils.getMatchingChilds(baseElement, "http://www.w3.org/2000/09/xmldsig#", "SignatureValue").item(0);
      Transform transform = new Transform(signatureValue.getOwnerDocument(), c14nMethodValue);
      XMLSignatureInput refData = transform.performTransform(new XMLSignatureInput(signatureValue));
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      if (refData.isByteArray()) {
         baos.write(refData.getBytes());
      } else if (refData.isOctetStream()) {
         baos.write(ConnectorIOUtils.getBytes(refData.getOctetStream()));
      }

      return baos.toByteArray();
   } catch (Exception var7) {
      throw new IllegalArgumentException("Unable to calculateDigest", var7);
   }
}
 
Example 5
Source File: XadesTSpecification.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private byte[] generateTimestampDigest(Element baseElement, String c14nMethodValue) {
   try {
      Node signatureValue = DomUtils.getMatchingChilds(baseElement, "http://www.w3.org/2000/09/xmldsig#", "SignatureValue").item(0);
      Transform transform = new Transform(signatureValue.getOwnerDocument(), c14nMethodValue);
      XMLSignatureInput refData = transform.performTransform(new XMLSignatureInput(signatureValue));
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      if (refData.isByteArray()) {
         baos.write(refData.getBytes());
      } else if (refData.isOctetStream()) {
         baos.write(ConnectorIOUtils.getBytes(refData.getOctetStream()));
      }

      return baos.toByteArray();
   } catch (Exception var7) {
      throw new IllegalArgumentException("Unable to calculateDigest", var7);
   }
}
 
Example 6
Source File: TimeStampDigestInputImpl.java    From xades4j with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void addToDigestInput(XMLSignatureInput refData, Document doc) throws CannotAddDataToDigestInputException
{
    try
    {
        if (refData.isNodeSet() || refData.isElement())
        {
            Transform c14nTransform = TransformUtils.createTransform(this.c14n, this.parametersMarshallingProvider, doc);
            refData = c14nTransform.performTransform(refData);
            // Fall through to add the bytes resulting from the canonicalization.
        }

        if (refData.isByteArray())
        {
            digestInput.write(refData.getBytes());
        } else if (refData.isOctetStream())
        {
            StreamUtils.readWrite(refData.getOctetStream(), digestInput);
        }
    }
    catch (Exception ex)
    {
        throw new CannotAddDataToDigestInputException(ex);
    }
}
 
Example 7
Source File: ManifestValidator.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
private byte[] getBytesAfterTransforms(Node nodeToTransform, final List<Transform> transforms) throws DSSException {
	try {
		XMLSignatureInput xmlSignatureInput = new XMLSignatureInput(nodeToTransform);
		for (Transform transform : transforms) {
			xmlSignatureInput = transform.performTransform(xmlSignatureInput);
		}
		return xmlSignatureInput.getBytes();
	} catch (Exception e) {
		throw new DSSException("An error occurred during applying of transformations. Transforms cannot be performed!", e);
	}
}