It is the upgrade of an existing signature to a more complex signature type.
The sample codes are in the package tr.gov.tubitak.uekae.esya.api.xades.example.upgrades
.
The signature upgrade is performed by calling the upgrade function of the signature object with the parameter stating the desired signature type. You can see the folder of the signature type to be upgraded from and the class of the signature type to be upgraded to. For example, the sample code for upgrading a BES signature to T type is in bes.UpgradeToT
.
// create context with working directory Context context = createContext(); // read signature to be upgraded XMLSignature signature = XMLSignature.parse(new FileDocument(new File(BASE_DIR + "bes.xml")),context); // upgrade to T signature.upgrade(SignatureType.ES_T); signature.write(new FileOutputStream(BASE_DIR + SIGNATURE_FILENAME));
As for the enveloped signatures, the signature must be extracted from the signed document , upgraded and reinserted to the signed document. The code is in enveloped.UpgradeToT
.
Since this type of signed documents have no standard structure, the signature extraction must be performed by the user. A sample code is listed in enveloped.UpgradeToT.
// create context with working directory Context context = createContext(); // parse the previously created enveloped signature org.w3c.dom.Document document = parseDoc(Enveloped.SIGNATURE_FILENAME, context); // get the signature in DOM document XMLSignature signature = readSignature(document, context); // upgrade the signature to type T signature.upgrade(SignatureType.ES_T); // writing enveloped XML to the file Source source = new DOMSource(document); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(source, new StreamResult(new FileOutputStream(BASE_DIR + SIGNATURE_FILENAME)));
The upgrade of parallel signatures requires the selection of the signatures to be upgraded. As for the enveloped signature, the extraction of the signature to be upgraded must be performed by the user.
The code is in parallel.UpgradeToT
.
// create context with working directory Context context = createContext(); // parse the previously created enveloped signature org.w3c.dom.Document document = parseDoc(ParallelDetached.SIGNATURE_FILENAME, context); // get and upgrade the signature 1 in DOM document XMLSignature signature1 = readSignature(document, context, 0); signature1.upgrade(SignatureType.ES_T); // get and upgrade the signature 2 in DOM document XMLSignature signature2 = readSignature(document, context, 1); signature2.upgrade(SignatureType.ES_T); // writing enveloped XML to the file Source source = new DOMSource(document); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(source, new StreamResult(new FileOutputStream(BASE_DIR + SIGNATURE_FILENAME)));