ESYAE-imza Kütüphaneleri

User Tools

Site Tools


en:esya:xades:kod-imza-atma-dogrulama

XAdES Signature API Sample Usages

You can find the sample codes in package tr.gov.tubitak.uekae.esya.api.xades.example .

İmza Atma

A sample signature creation code takes place under the folder formats in the class BES.

// 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));

Signature Verification

Here is a simple signature verification code. The signature is loaded from a file and the signing certificate is included in the signed document.

XMLSignature signature = XMLSignature.parse( new FileDocument(new File(FILE_NAME)), new Context(BASE_DIR)) ; 
// no params, use the certificate in key info 
ValidationResult result = signature.verify();
Note that ,only the outermost signature is verified in this example. For the verification of a counter signature, see validation.Validation. You can perform the verification of parallel signatures by using the method validateParallel of the same class.

Smartcard Operations

For detailed information about Smartcard API, see smartcard user manual. In order to create signature by using smartcard an object of the corresponding BaseSigner child class must be created. Since the private key is stored in the smartcard and can not be extracted, there is no parameter used for the private key. The class SmartCardManager provides basic functionality for smartcard operations.

en/esya/xades/kod-imza-atma-dogrulama.txt · Son değiştirilme: 2013/09/11 06:03 Değiştiren: Dindar Öz