Package com.itextpdf.text.pdf.security
Class MakeXmlSignature
java.lang.Object
com.itextpdf.text.pdf.security.MakeXmlSignature
Class that signs your XML.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Empty class for key simulation -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static XMLSignatureFactory
private static Element
findElement
(NodeList nodes, String localName) Find Signature and SignatureValue elements after marshalization.private static Reference
generateContentReference
(XMLSignatureFactory fac, XmlSignatureAppearance sap, String referenceId) private static Reference
generateCustomReference
(XMLSignatureFactory fac, String uri, String type, String id) private static KeyInfo
generateKeyInfo
(Certificate[] chain, XmlSignatureAppearance sap) private static KeyInfo
generateKeyInfo
(PublicKey publicKey) private static XMLObject
generateXadesObject
(XMLSignatureFactory fac, XmlSignatureAppearance sap, String signatureId, String contentReferenceId, String signedPropertiesId, String[] signaturePolicy) private static byte[]
getByteArrayOfNode
(Node node) private static String
private static String
private static String
private static void
sign
(XMLSignatureFactory fac, ExternalSignature externalSignature, XmlLocator locator, org.apache.jcp.xml.dsig.internal.dom.DOMSignedInfo si, XMLObject xo, KeyInfo ki, String signatureId) static void
signXades
(XmlSignatureAppearance sap, ExternalSignature externalSignature, Certificate[] chain, boolean includeSignaturePolicy) Signs the xml with XAdES BES using the enveloped mode, with optional xpath transform (see XmlSignatureAppearance).static void
signXadesBes
(XmlSignatureAppearance sap, ExternalSignature externalSignature, Certificate[] chain) Signs the xml with XAdES BES using the enveloped mode, with optional xpath transform (see XmlSignatureAppearance).static void
signXadesEpes
(XmlSignatureAppearance sap, ExternalSignature externalSignature, Certificate[] chain) Signs the xml with XAdES BES using the enveloped mode, with optional xpath transform (see XmlSignatureAppearance).static void
signXmlDSig
(XmlSignatureAppearance sap, ExternalSignature externalSignature, Certificate[] chain) Signs the xml with XmlDSig using the enveloped mode, with optional xpath transform (see XmlSignatureAppearance).static void
signXmlDSig
(XmlSignatureAppearance sap, ExternalSignature externalSignature, PublicKey publicKey) Signs the xml with XmlDSig using the enveloped mode, with optional xpath transform (see XmlSignatureAppearance).static void
signXmlDSig
(XmlSignatureAppearance sap, ExternalSignature externalSignature, KeyInfo keyInfo) Signs the xml with XmlDSig using the enveloped mode, with optional xpath transform (see XmlSignatureAppearance).private static void
verifyArguments
(XmlSignatureAppearance sap, ExternalSignature externalSignature)
-
Constructor Details
-
MakeXmlSignature
public MakeXmlSignature()
-
-
Method Details
-
signXmlDSig
public static void signXmlDSig(XmlSignatureAppearance sap, ExternalSignature externalSignature, KeyInfo keyInfo) throws GeneralSecurityException, IOException, DocumentException Signs the xml with XmlDSig using the enveloped mode, with optional xpath transform (see XmlSignatureAppearance).- Parameters:
sap
- the XmlSignatureAppearanceexternalSignature
- the interface providing the actual signingkeyInfo
- KeyInfo for verification- Throws:
GeneralSecurityException
IOException
DocumentException
-
signXmlDSig
public static void signXmlDSig(XmlSignatureAppearance sap, ExternalSignature externalSignature, Certificate[] chain) throws DocumentException, GeneralSecurityException, IOException Signs the xml with XmlDSig using the enveloped mode, with optional xpath transform (see XmlSignatureAppearance).- Parameters:
sap
- the XmlSignatureAppearanceexternalSignature
- the interface providing the actual signingchain
- the certificate chain- Throws:
GeneralSecurityException
IOException
DocumentException
-
signXmlDSig
public static void signXmlDSig(XmlSignatureAppearance sap, ExternalSignature externalSignature, PublicKey publicKey) throws GeneralSecurityException, DocumentException, IOException Signs the xml with XmlDSig using the enveloped mode, with optional xpath transform (see XmlSignatureAppearance).- Parameters:
sap
- the XmlSignatureAppearanceexternalSignature
- the interface providing the actual signingpublicKey
- PublicKey for verification- Throws:
GeneralSecurityException
IOException
DocumentException
-
signXades
public static void signXades(XmlSignatureAppearance sap, ExternalSignature externalSignature, Certificate[] chain, boolean includeSignaturePolicy) throws GeneralSecurityException, DocumentException, IOException Signs the xml with XAdES BES using the enveloped mode, with optional xpath transform (see XmlSignatureAppearance).- Parameters:
sap
- the XmlSignatureAppearanceexternalSignature
- the interface providing the actual signingchain
- the certificate chainincludeSignaturePolicy
- if true SignaturePolicyIdentifier will be included (XAdES-EPES)- Throws:
GeneralSecurityException
IOException
DocumentException
-
signXadesBes
public static void signXadesBes(XmlSignatureAppearance sap, ExternalSignature externalSignature, Certificate[] chain) throws GeneralSecurityException, DocumentException, IOException Signs the xml with XAdES BES using the enveloped mode, with optional xpath transform (see XmlSignatureAppearance).- Parameters:
sap
- the XmlSignatureAppearanceexternalSignature
- the interface providing the actual signingchain
- the certificate chain- Throws:
GeneralSecurityException
IOException
DocumentException
-
signXadesEpes
public static void signXadesEpes(XmlSignatureAppearance sap, ExternalSignature externalSignature, Certificate[] chain) throws GeneralSecurityException, DocumentException, IOException Signs the xml with XAdES BES using the enveloped mode, with optional xpath transform (see XmlSignatureAppearance).- Parameters:
sap
- the XmlSignatureAppearanceexternalSignature
- the interface providing the actual signingchain
- the certificate chain- Throws:
GeneralSecurityException
IOException
DocumentException
-
verifyArguments
private static void verifyArguments(XmlSignatureAppearance sap, ExternalSignature externalSignature) throws DocumentException - Throws:
DocumentException
-
findElement
Find Signature and SignatureValue elements after marshalization. -
generateKeyInfo
-
generateKeyInfo
- Throws:
GeneralSecurityException
-
getRandomId
-
createSignatureFactory
-
generateXadesObject
private static XMLObject generateXadesObject(XMLSignatureFactory fac, XmlSignatureAppearance sap, String signatureId, String contentReferenceId, String signedPropertiesId, String[] signaturePolicy) throws GeneralSecurityException - Throws:
GeneralSecurityException
-
getX509IssuerName
-
getX509SerialNumber
-
generateContentReference
private static Reference generateContentReference(XMLSignatureFactory fac, XmlSignatureAppearance sap, String referenceId) throws GeneralSecurityException - Throws:
GeneralSecurityException
-
generateCustomReference
private static Reference generateCustomReference(XMLSignatureFactory fac, String uri, String type, String id) throws GeneralSecurityException - Throws:
GeneralSecurityException
-
sign
private static void sign(XMLSignatureFactory fac, ExternalSignature externalSignature, XmlLocator locator, org.apache.jcp.xml.dsig.internal.dom.DOMSignedInfo si, XMLObject xo, KeyInfo ki, String signatureId) throws DocumentException - Throws:
DocumentException
-
getByteArrayOfNode
-