एक c14n अनन्य जोड़ने पर अवैध है, तो यह एक्सएमएल हस्ताक्षर उत्पन्न करने के लिए अपने कोड है:XML हस्ताक्षर को बदलने
DOMSignContext dsc = new DOMSignContext
(prk, xmldoc.getDocumentElement());
XMLSignatureFactory fac =
XMLSignatureFactory.getInstance("DOM");
DigestMethod digestMethod =
fac.newDigestMethod("http://www.w3.org/2000/09/xmldsig#sha1", null);
C14NMethodParameterSpec spec = null;
CanonicalizationMethod cm = fac.newCanonicalizationMethod(
"http://www.w3.org/2001/10/xml-exc-c14n#",spec);
SignatureMethod sm = fac.newSignatureMethod(
"http://www.w3.org/2000/09/xmldsig#rsa-sha1",null);
ArrayList transformList = new ArrayList();
TransformParameterSpec transformSpec = null;
Transform envTransform = fac.newTransform("http://www.w3.org/2000/09/xmldsig#enveloped-signature",transformSpec);
Transform exc14nTransform = fac.newTransform(
"http://www.w3.org/2001/10/xml-exc-c14n#",transformSpec);
transformList.add(exc14nTransform);
transformList.add(envTransform);
Reference ref = fac.newReference("",digestMethod,transformList,null,null);
ArrayList refList = new ArrayList();
refList.add(ref);
SignedInfo si =fac.newSignedInfo(cm,sm,refList);
यह एक संदर्भ के रूप में मान्यता गलत है और यह भी कोर वैधता के रूप में झूठी देता है। लेकिन जब मैं envTrasnform
चर यानी fac.new Transform("http://www.w3.org/2001/10/xml-exc-c14n#",transformSpec)
को हटा दें और निम्न कोड के साथ निष्पादित करें:
DOMSignContext dsc = new DOMSignContext
(prk, xmldoc.getDocumentElement());
XMLSignatureFactory fac =
XMLSignatureFactory.getInstance("DOM");
DigestMethod digestMethod =
fac.newDigestMethod("http://www.w3.org/2000/09/xmldsig#sha1", null);
C14NMethodParameterSpec spec = null;
CanonicalizationMethod cm = fac.newCanonicalizationMethod(
"http://www.w3.org/2001/10/xml-exc-c14n#",spec);
SignatureMethod sm = fac.newSignatureMethod(
"http://www.w3.org/2000/09/xmldsig#rsa-sha1",null);
ArrayList transformList = new ArrayList();
TransformParameterSpec transformSpec = null;
Transform envTransform = fac.newTransform(
"http://www.w3.org/2000/09/xmldsig#enveloped-signature",transformSpec);
transformList.add(envTransform);
Reference ref = fac.newReference("",digestMethod,transformList,null,null);
ArrayList refList = new ArrayList();
refList.add(ref);
SignedInfo si =fac.newSignedInfo(cm,sm,refList);
यह सच कोर वैधता और संदर्भ वैधता देता है। ये क्यों हो रहा है। मुझे यह कोड फॉर्म this लिंक मिला है (लिफाफा हस्ताक्षर अनुभाग बनाने में कोड खंड 2)।