Bu sayfanın seçili sürümü ile mevcut sürümü arasındaki farkları gösterir.
esya:xades:kod-e-fatura [2013/08/29 07:41] Ahmet Yetgin |
esya:xades:kod-e-fatura [2013/10/09 06:12] (mevcut) Süleyman Uslu |
||
---|---|---|---|
Satır 1: | Satır 1: | ||
====== E-Fatura ====== | ====== E-Fatura ====== | ||
+ | |||
+ | |||
+ | 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. | ||
+ | |||
E-fatura kendine has formatı olan bir XML dökümanıdır. E-faturaların imzalanması ise [[:esya:xades:kod-imza-yapilari|İmza Yapıları]] altında açıklanan zarflanmış imzaya çok benzemektedir. Yalnız farklı olarak imza, fatura içinde e-fatura standartı için belirlenmiş özel bir alana konulmalıdır. | E-fatura kendine has formatı olan bir XML dökümanıdır. E-faturaların imzalanması ise [[:esya:xades:kod-imza-yapilari|İmza Yapıları]] altında açıklanan zarflanmış imzaya çok benzemektedir. Yalnız farklı olarak imza, fatura içinde e-fatura standartı için belirlenmiş özel bir alana konulmalıdır. | ||
+ | |||
<sxh java> | <sxh java> | ||
- | // get the element that signature will be added | + | //get the element that signature will be added |
- | Element exts = (Element)faturaDoc.getDocumentElement().getElementsByTagName("ext:UBLExtensions").item(0); | + | Element extContent = (Element)faturaDoc.getDocumentElement().getElementsByTagName("ext:ExtensionContent").item(0); |
- | Element ext = (Element)exts.getElementsByTagName("ext:UBLExtension").item(0); | + | |
- | Element extContent = (Element)exts.getElementsByTagName("ext:ExtensionContent").item(0); | + | |
- | // generate signature | + | // generate signature Context context = createContext(); |
- | Context context = createContext(); | + | |
context.setDocument(faturaDoc); | context.setDocument(faturaDoc); | ||
XMLSignature signature = new XMLSignature(context, false); | XMLSignature signature = new XMLSignature(context, false); | ||
- | // attach signature to envelope structure | + | |
+ | //attach signature to envelope structure | ||
extContent.appendChild(signature.getElement()); | extContent.appendChild(signature.getElement()); | ||
</sxh> | </sxh> | ||
Satır 24: | Satır 27: | ||
transforms.addTransform(new Transform(context, TransformType.ENVELOPED.getUrl())); | transforms.addTransform(new Transform(context, TransformType.ENVELOPED.getUrl())); | ||
- | // add whole document(="") with envelope transform, with SHA256 | + | //add whole document(="") with envelope transform, with SHA256 |
- | // and don't include it into signature(false) | + | //and don't include it into signature(false) |
signature.addDocument("", "text/xml", transforms, DigestMethod.SHA_256, false); | signature.addDocument("", "text/xml", transforms, DigestMethod.SHA_256, false); | ||
</sxh> | </sxh> | ||
Satır 32: | Satır 35: | ||
<sxh java> | <sxh java> | ||
- | // add signer role information | + | //add signer role information |
SignerRole rol = new SignerRole(context, new ClaimedRole[]{new ClaimedRole(context, "Supplier")}); | SignerRole rol = new SignerRole(context, new ClaimedRole[]{new ClaimedRole(context, "Supplier")}); | ||
signature.getQualifyingProperties().getSignedSignatureProperties().setSignerRole(rol); | signature.getQualifyingProperties().getSignedSignatureProperties().setSignerRole(rol); | ||
- | // e-fatura standard wants public key info in the signature | + | //e-fatura standard wants public key info in the signature |
PublicKey pk = KeyUtil.decodePublicKey(new ECertificate(cert.getEncoded()).getSubjectPublicKeyInfo()); | PublicKey pk = KeyUtil.decodePublicKey(new ECertificate(cert.getEncoded()).getSubjectPublicKeyInfo()); | ||
signature.getKeyInfo().add(new KeyValue(context, pk)); | signature.getKeyInfo().add(new KeyValue(context, pk)); | ||
Satır 42: | Satır 45: | ||
// add signing time | // add signing time | ||
signature.getQualifyingProperties().getSignedSignatureProperties().setSigningTime(getTime()); | 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> | </sxh> | ||
Kodu ''tr.gov.tubitak.uekae.esya.api.xades.example.efatura.EFatura'' altında inceleyebilirsiniz. | Kodu ''tr.gov.tubitak.uekae.esya.api.xades.example.efatura.EFatura'' altında inceleyebilirsiniz. |