Bu sayfanın seçili sürümü ile mevcut sürümü arasındaki farkları gösterir.
esya:xades:kod-e-fatura [2013/10/09 06:02] Süleyman Uslu |
esya:xades:kod-e-fatura [2013/10/09 06:12] (mevcut) Süleyman Uslu |
||
---|---|---|---|
Satır 8: | Satır 8: | ||
- | <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); | + | <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())); | + | //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. | ||
- | //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> 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. // __ // | + | <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. |