Bu sayfanın seçili sürümü ile mevcut sürümü arasındaki farkları gösterir.
en:esya:xades:kod-imza-atma-dogrulama [2013/09/11 06:00] Dindar Öz |
en:esya:xades:kod-imza-atma-dogrulama [2013/09/11 06:03] (mevcut) Dindar Öz |
||
---|---|---|---|
Satır 8: | Satır 8: | ||
- | <sxh java> //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); | + | <sxh java> |
+ | // create context with working directory | ||
+ | Context context = createContext(); | ||
+ | // create signature according to context, | ||
+ | // with default type (XADES_BES) | ||
+ | XMLSignature signature = new XMLSignature(context); | ||
- | //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)); | + | // 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); | ||
- | signature.write(new FileOutputStream(BASE_DIR + SIGNATURE_FILENAME)); </sxh> | + | // 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)); | ||
+ | </sxh> | ||
===== Signature Verification ===== | ===== Signature Verification ===== | ||
Satır 20: | Satır 38: | ||
- | <sxh java> XMLSignature signature = XMLSignature.parse( new FileDocument(new File(FILE_NAME)), new Context(BASE_DIR)) ; //noparams, use the certificate in key info ValidationResult result = signature.verify(); </sxh> 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. | + | <sxh java> |
+ | 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(); | ||
+ | </sxh> | ||
+ | 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 ===== | ===== 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. | 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. | ||
// | // |