[Java] [XML signature] Add prefix and ID to Signature tag

A note on the handling of Signature tags in Java XML signatures.

If you want to add the prefix "dsig" to the Signature tag

createXml.java


//Creating a signature context
//Prefix Signature tags (including all child elements) with setDefaultNamespacePrefix
DOMSignContext dsc = new DOMSignContext(privateKey, document.getDocumentElement());
dsc.setDefaultNamespacePrefix("dsig");

If you want to give an ID to the Signature tag

createXml.java


XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM");

(Omission)

//Sign.
//Set the ID in the 4th argument of newXMLSignature
XMLSignature signature = fac.newXMLSignature(si, ki, null, "a", null);
signature.sign(dsc);

Reference site (English)

How to add namespace while signing XML file using javax.xml.crypto.dsig.*? add attribute to signature xml in java

Recommended Posts

[Java] [XML signature] Add prefix and ID to Signature tag
Implement XML signature in Java
Add multi-letter watermark to Java Word
Add watermark to Java to PDF document
[Java] Add WordArt to Word document
Add / remove watermark to Java PowerPoint
[Rails 6] cocoon_ Add id and data attributes to the form to be added
Convert Java org.w3c.dom.Document objects and XML strings
[Java] How to add data to List (add, addAll)
Java implementation to create and solve mazes
[Java] How to output and write files!
[Rails] [Memo] When to add = to <%%> and when not
Add Document to Azure Search Service (Java)
[Introduction to Java] Variable declarations and types
Add footnotes to Word documents in Java
Java to C and C to Java in Android Studio
Add spring boot and gradle to eclipse
Add SameSite attribute to cookie in Java
Java (add2)
Java (add)
Kotlin functions and lambdas to send to Java developers
[Java] How to use FileReader class and BufferedReader class
[Java] Add quotes only to specific CSV columns
[Java] How to get and output standard input
Add a tag function to Rails. Use acts-as-taggable-on
Java upload and download notes to Azure storage
Add, read, and delete Excel comments in Java
How to get and study java SE8 Gold
Java8 to start now ~ forEach and lambda expression ~
[Java] Article to add validation with Spring Boot 2.3.1.
How to access Java Private methods and fields
[Java] How to use Calendar class and Date class