ESYAE-imza Kütüphaneleri

User Tools

Site Tools


esya:xades:kod-e-fatura

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ı

esya:xades:kod-e-fatura [2013/10/02 08:12]
Süleyman Uslu
esya:xades:kod-e-fatura [2013/10/09 06:12] (mevcut)
Süleyman Uslu
Satır 2: Satır 2:
  
  
-Not: .NET ile e-fatura imzalanacağı vakit, XML yapısında olan +Not: .NET ile e-fatura imzalanacağı vakit, XML yapısında olan faturanın düzgün bir şekilde okunup işlenmesi gerekiyor. Okuma kod örneği için ''​tr.gov.tubitak.uekae.esya.api.xades.example.utils.SampleBase''​ sınıfının ''​newEnvelope(String)''​ metodunu inceleyiniz.
  
  
Satır 8: Satır 8:
  
  
-<sxh java> //get the element that signature will be added Element ​exts = (Element)faturaDoc.getDocumentElement().getElementsByTagName("​ext:​UBLExtensions"​).item(0);​ Element ext = (Element)exts.getElementsByTagName("​ext:​UBLExtension"​).item(0);​ Element extContent = (Element)exts.getElementsByTagName("​ext:​ExtensionContent"​).item(0);  // generate signature Context context = createContext();​ context.setDocument(faturaDoc);​ XMLSignature signature = new XMLSignature(context,​ false); //attach signature to envelope structure extContent.appendChild(signature.getElement());​ </​sxh> ​ Ardından bütün dökümanın dahil edildiği yalnız imza alanının hariç bırakıldığı transform metodu eklenir. ​ <sxh java> // use enveloped signature transform Transforms transforms = new Transforms(context);​ transforms.addTransform(new Transform(context,​ TransformType.ENVELOPED.getUrl()));+<sxh java> 
 +//get the element that signature will be added 
 +Element ​extContent ​= (Element)faturaDoc.getDocumentElement().getElementsByTagName("​ext:​ExtensionContent"​).item(0);​
  
 +// generate signature Context context = createContext();​
 +context.setDocument(faturaDoc);​
 +XMLSignature signature = new XMLSignature(context,​ false);
  
-//add whole document(=_fckg_QUOT__fckg_QUOT_____) with envelope ​transform, with SHA256 //and don't include it into signature(false) signature.addDocument("",​ "​text/​xml",​ transforms, DigestMethod.SHA_256,​ false); </​sxh> ​ Daha sonra ise yine e-fatura standartlarında gerekli kılınan imzacı rolü, açık anahtar ve imza zamanı eklenir. ​ <sxh java> // add signer role information SignerRole rol = new SignerRole(context,​ new ClaimedRole[]{new ClaimedRole(context,​ "​Supplier"​)}); ​signature.getQualifyingProperties().getSignedSignatureProperties().setSignerRole(rol); ​ //e-fatura standard wants public key info in the signature PublicKey pk = KeyUtil.decodePublicKey(new ECertificate(cert.getEncoded()).getSubjectPublicKeyInfo());​ signature.getKeyInfo().add(new KeyValue(context,​ pk));  // add signing time signature.getQualifyingProperties().getSignedSignatureProperties().setSigningTime(getTime()); </​sxh> ​ Kodu ''​tr.gov.tubitak.uekae.esya.api.xades.example.efatura.EFatura''​ altında inceleyebilirsiniz. __ // +//attach signature to envelope ​structure 
 +extContent.appendChild(signature.getElement()); 
 +</​sxh>​
  
 +Ardından bütün dökümanın dahil edildiği yalnız imza alanının hariç bırakıldığı transform metodu eklenir.
  
-//____ // +<sxh java> 
 +// use enveloped signature transform 
 +Transforms transforms = new Transforms(context);​ 
 +transforms.addTransform(new Transform(context,​ TransformType.ENVELOPED.getUrl()));​
  
 +//add whole document(=""​) with envelope transform, with SHA256
 +//and don't include it into signature(false)
 +signature.addDocument("",​ "​text/​xml",​ transforms, DigestMethod.SHA_256,​ false);
 +</​sxh>​
  
-//____ //+Daha sonra ise yine e-fatura standartlarında gerekli kılınan imzacı rolü, açık anahtar ve imza zamanı eklenir.
  
 +<sxh java>
 +//add signer role information
 +SignerRole rol = new SignerRole(context,​ new ClaimedRole[]{new ClaimedRole(context,​ "​Supplier"​)});​
 +signature.getQualifyingProperties().getSignedSignatureProperties().setSignerRole(rol);​
 +
 +//e-fatura standard wants public key info in the signature
 +PublicKey pk = KeyUtil.decodePublicKey(new ECertificate(cert.getEncoded()).getSubjectPublicKeyInfo());​
 +signature.getKeyInfo().add(new KeyValue(context,​ pk));
 +
 +// add signing time
 +signature.getQualifyingProperties().getSignedSignatureProperties().setSigningTime(getTime());​
 +</​sxh>​
 +
 +.NET kütüphanesinde ise açık anahtar eklemede ufak bir fark var.
 +
 +<sxh c#>
 +// e-fatura standards want public key info to be in the signature
 +signature.KeyInfo.add(new KeyValue(context,​ cert.asX509Certificate2().PublicKey.Key));​
 +</​sxh>​
 +
 +Yine e-fatura kuralı olarak, imzanın id'si, yani signature-id bölümü faturada belirtilen id'ye çevrilir.
 +
 +<sxh java>
 +//e-fatura standards want signatureID to be same with cbc:URI
 +// get signatureID from e-fatura
 +String signatureID = ((Element)(faturaDoc.getDocumentElement().getElementsByTagName("​cbc:​URI"​).item(0)) ).getTextContent();​
 +String signatureIDwoNumberSign = signatureID.substring(1);​
 +
 +//change original signatureID
 +Element dsSignature = (Element)(faturaDoc.getDocumentElement().getElementsByTagName("​ds:​Signature"​).item(0));​
 +dsSignature.setAttribute("​Id",​ signatureIDwoNumberSign);​
 +</​sxh>​
 +
 +Kodu ''​tr.gov.tubitak.uekae.esya.api.xades.example.efatura.EFatura''​ altında inceleyebilirsiniz.
esya/xades/kod-e-fatura.1380701559.txt.gz · Son değiştirilme: 2013/10/02 08:12 Değiştiren: Süleyman Uslu