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 İ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>
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);
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(=_fckg_QUOTfckg_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>
.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 = 1) ).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.