The sample codes for creating different types of signatures stated in the standarts are listed below. See the section Signature Types for the information about signature types
The sample codes are in the package tr.gov.tubitak.uekae.esya.api.xades.example.formats
.
BES
signature creation is as follows:
// create context with working directory Context context = createContext(); // create signature according to context, // with default type (XADES_BES) XMLSignature signature = new XMLSignature(context); // add document as reference, but do not embed it // into the signature (embed=false) signature.addDocument("./sample.txt", "text/plain", false); signature.getSignedInfo().setSignatureMethod(SignatureMethod.RSA_SHA256); // false-true gets non-qualified certificates while true-false gets qualified ones X509Certificate cert = JSmartCardManager.getInstance().getSignatureCertificate(true, false); // add certificate to show who signed the document signature.addKeyInfo(new ECertificate(cert.getEncoded())); // now sign it by using smart card signature.sign(JSmartCardManager.getInstance().getSigner(PIN, cert)); signature.write(new FileOutputStream(BASE_DIR + SIGNATURE_FILENAME));
T
signature creation is as follows:
// create context with working directory Context context = createContext(); // create signature according to context, // with default type (XADES_BES) XMLSignature signature = new XMLSignature(context); // add document as reference, but do not embed it // into the signature (embed=false) signature.addDocument("./sample.txt", "text/plain", false); signature.getSignedInfo().setSignatureMethod(SignatureMethod.RSA_SHA256); // false-true gets non-qualified certificates while true-false gets qualified ones X509Certificate cert = JSmartCardManager.getInstance().getSignatureCertificate(true, false); // add certificate to show who signed the document signature.addKeyInfo(new ECertificate(cert.getEncoded())); // now sign it by using smart card signature.sign(JSmartCardManager.getInstance().getSigner(PIN, cert)); // upgrade to T signature.upgrade(SignatureType.ES_T); signature.write(new FileOutputStream(BASE_DIR + SIGNATURE_FILENAME));
C
signature creation is as follows:
The difference is the upgrade line, which is ES_C
in this case.
// upgrade to C signature.upgrade(SignatureType.ES_C);
X1
signature creation is as follows:
The difference is the upgrade line, which is ES_X_Type1
in this case.
// upgrade to X1 signature.upgrade(SignatureType.ES_X_Type1);
X2
signature creation is as follows.
The difference is the upgrade line, which is ES_X_Type2
in this case.
// upgrade to X2 signature.upgrade(SignatureType.ES_X_Type2);
XL
signature creation is as follows:
The difference is the upgrade line, which is ES_XL
in this case.
// upgrade to XL signature.upgrade(SignatureType.ES_XL);
A
signature creation is as follows:
The difference is the upgrade line, which is ES_A
in this case.
// upgrade to A signature.upgrade(SignatureType.ES_A);