====== Signature Attributes ======
The attributes listed in the standarts can be added to XAdES signatures.
The sample codes are in the package ''tr.gov.tubitak.uekae.esya.api.xades.example.attributes''.
===== Signing Time =====
It adds the time of signature creation ,which is stated by the signer, to the signed document
See ''SigningTimeAttribute''.
// 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()));
// add signing time
signature.getQualifyingProperties().getSignedSignatureProperties().setSigningTime(getTime());
// now sign it by using smart card
signature.sign(JSmartCardManager.getInstance().getSigner(PIN, cert));
signature.write(new FileOutputStream(BASE_DIR + SIGNATURE_FILENAME));
===== Signing Production Place =====
It states the location of the signature creation.
See ''SignatureProductionPlaceAttribute'' .
// add signature production place
signature.getQualifyingProperties().getSignedSignatureProperties().setSignatureProductionPlace(
new SignatureProductionPlace(context, "Istanbul", "Marmara", "34470", "Turkey"));
===== Signer Role =====
It contains additional information about the signer.
See ''SignerRoleAttribute''.
// add signer role
signature.getQualifyingProperties().getSignedSignatureProperties().setSignerRole(
new SignerRole(context, new ClaimedRole[]{new ClaimedRole(context, "Manager")}));
===== Commitment Type Indication =====
It specifies the commitment type of the signed document.
See ''CommitmentTypeIndicationAttribute''.
// 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
String ref1 = "#"+signature.addDocument("./sample.txt", "text/plain", true);
String objId2 = signature.addPlainObject("Test data 1.", "text/plain", null);
String ref2 = "#"+signature.addDocument("#"+objId2, null, 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()));
// add commitment type indication
signature.getQualifyingProperties().getSignedProperties().createOrGetSignedDataObjectProperties().
addCommitmentTypeIndication(createTestCTI(context,ref1,ref2));
// now sign it by using smart card
signature.sign(JSmartCardManager.getInstance().getSigner(PIN, cert));
signature.write(new FileOutputStream(BASE_DIR + SIGNATURE_FILENAME));
===== Timestamp for All Data Objects =====
It contains the timestamp for all documents.
See ''AllDataObjectsTimeStampAttribute''.
// add all data objects timestamp
signature.getQualifyingProperties().getSignedProperties().createOrGetSignedDataObjectProperties().
addAllDataObjectsTimeStamp(new AllDataObjectsTimeStamp(context,signature));
===== Timestamp for Individual Data Object =====
It contains the timestamp taken overs the documents seperately.
See ''IndividualDataObjectTimeStampAttribute''.
// 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 into the signature and get the reference
String ref1 = "#" + signature.addDocument("./sample.txt", "text/plain", true);
// add another object
String objId2 = signature.addPlainObject("Test Data 1", "text/plain", null);
String ref2 = "#" + signature.addDocument("#"+objId2, null, 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()));
// create new individual data objects timestamp structure
IndividualDataObjectsTimeStamp timestamp = new IndividualDataObjectsTimeStamp(context);
// add objects to timestamp structure
timestamp.addInclude(new Include(context, ref1, Boolean.TRUE));
timestamp.addInclude(new Include(context, ref2, Boolean.TRUE));
// get encapsulated timestamp to individual data objects timestamp
timestamp.addEncapsulatedTimeStamp(signature);
// add individual data objects timestamp to signature
signature.getQualifyingProperties().getSignedProperties().createOrGetSignedDataObjectProperties().
addIndividualDataObjectsTimeStamp(timestamp);
// optional - add timestamp validation data
signature.addTimeStampValidationData(timestamp, Calendar.getInstance());
// now sign it by using smart card
signature.sign(JSmartCardManager.getInstance().getSigner(PIN, cert));
signature.write(new FileOutputStream(BASE_DIR + SIGNATURE_FILENAME));