ESYAE-imza Kütüphaneleri

User Tools

Site Tools


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

Farklar

Bu sayfanın seçili sürümü ile mevcut sürümü arasındaki farkları gösterir.

Karşılaştırma görünümüne bağlantı

en:esya:xades:kod-imza-atma-dogrulama [2013/09/11 05:47]
Dindar Öz
en:esya:xades:kod-imza-atma-dogrulama [2013/09/11 06:03] (mevcut)
Dindar Öz
Satır 5: Satır 5:
 ===== İmza Atma ===== ===== İmza Atma =====
  
 +A sample signature creation code takes place under the folder ''​formats''​ in the class ''​BES''​.
  
-''​formats''​altında ''​BES''​sınıfındaki kod ile örnek bir imza atabilirsiniz. 
  
 +<sxh java>
 +// create context with working directory
 +Context context = createContext();​
  
-<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);+// 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);
  
-//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.getSignedInfo().setSignatureMethod(SignatureMethod.RSA_SHA256);
  
 +// false-true gets non-qualified certificates while true-false gets qualified ones
 +X509Certificate cert = JSmartCardManager.getInstance().getSignatureCertificate(true,​ false);
  
-signature.write(new FileOutputStream(BASE_DIR + SIGNATURE_FILENAME)); </​sxh>​ +// add certificate to show who signed the document 
-===== İmza Doğrulama =====+signature.addKeyInfo(new ECertificate(cert.getEncoded()));
  
 +// now sign it by using smart card
 +signature.sign(JSmartCardManager.getInstance().getSigner(PIN,​ cert));
  
-Basit bir doğrulama kod örneği. Bu örnekte imza dosyadan yüklenmekte ve imza içerisinde yer alan imzalama sertifikası kullanılarak doğrulanmaktadır.+signature.write(new FileOutputStream(BASE_DIR + SIGNATURE_FILENAME));​ 
 +</​sxh>​ 
 +===== 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.
  
-<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>​ Bu örnekte yalnız ana imzanın doğrulaması yapıldığına dikkat edilmelidir. Seri imza doğrulaması da yapan örnek kod için ''​validation.Validation''​sınıfına göz atabilirsiniz. Yine aynı sınıftaki''​validateParallel''​fonksiyonu ile de paralel imzaların doğrulamasını gerçekleştirebilirsiniz. ===== Akıllı Kart İşlemleri ===== Akıllı kartkütüphanesinin detaylı kullanımı için akıllı kart kullanım kılavuzuna göz atınız. Akılı kart kullanarak imzalama yapmak için uygun BaseSignersınıfı oluşturmalısınız. Gizli anahtar kart içinde bulunduğu için imza kütüphanesine parametre olarak verilemez. Kütüphane ile dağıtılan''​SmartCardManager''​sınıfı başlangıç için yeterli seviyede akıllı kart ihtiyaçlarını görmektedir.//​ 
  
 +<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 ===== 
 +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.1378878476.txt.gz · Son değiştirilme: 2013/09/11 05:47 Değiştiren: Dindar Öz