Signature ( firma formateado ) alguien sabe. (SIN FORMATO XML)
Publicado por Jeremy Gonzalez (1 intervención) el 12/10/2016 22:00:10
Hola, quería saber si alguien sabe como dejar formateada la firma xml generada con signature.
No utilizando
porque funciona, pero me degenera la firama digestvalue.
la firmo con estoy el documento xml .
Resultado
<LibroC xmlns="http://www.dddd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" xsi:schemaLocation="http://www.sd.xsd">
<EnvioLibro ID="ID201610">
<Hola><Hola>
</EnvioLibro> (Salto... pero despues no hay salto de linea en la etiqueta signature)
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><DigestValue>G0MRzIx+883NUS9IeyWuB+ST+O0=</DigestValue></Reference></SignedInfo><SignatureValue>W8Aofr6/ajWPj/frXQEnMCyoiA50N1KUMXTcBa1OHMzgf6OGJTobRYEWnaCffBPpCSis67VIVvzu
CGquJ4d2+pgRxCRneYAsVD+0gQEJM20mYJU7rN5GKpAQjELh5alwDEhseQMHsaGNTE5qQlrsHQDa
uTHvwKNdbKLEsUm4DL6BIyi6ymRJHGnNN2NBFw==</SignatureValue><KeyInfo><KeyValue><RSAKeyValue><Modulus>ppaEZipVitUq09iwFC4MXpbOSweZMhxvaMhej9Knib0ek+v9D8MU/t9u5duK0cZt0Qd7uLG5r4e7
fYPd++glqizW43IvN3TeWTIz6/dtZE7a9Ri9ae6xZxRkeutO/ZdcUBP8KJ0g+E23HEHbpGlXTByP
6nywdZH5oC0tnI5y2dRx8UqmRnXPCF5Aq2QyG+IAgLZ7CgWU3uj8BzCGALAraZaCneV6IGWupOkb
k7L8oPa7yM3/UCSKK3aq9tn95H4AvzDpUC+qaQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue><X509Data><X509Certificate>MIIGUjCCBTqgAwIBAgIIJklLQgmUzQ4wDQYJKoZIhvcNAQELBQAwga8xCzAJBgNVBAYTAkNMMRQw
EgYDVQQKDAtFLVNpZ24gUy5BLjE5MDcGA1UECwwwVGVybXMgb2YgdXNlIGF0IHd3dy5lc2lnbi1s
YS5jb20vYWN1ZXJkb3RlcmNlcm9zMSswKQYDVQQDDCJFLVNpZ24gQ2xhc3MgMiBGaXJtYSBUcmli
....
7bx2CcLBJ/EUDh4i8jBHkoq7D92dUY/En2s=</X509Certificate></X509Data></KeyInfo></Signature></LibroC>
Si alguien sabe como formatear el xml signature y que quede bien la firma.
He leido por todos lados y noo encuento una solución.
pls alguna ayuda..
No utilizando
1
2
Transformer trans = tf.newTransformer();
trans.setOutputProperty(OutputKeys.INDENT, "yes");
porque funciona, pero me degenera la firama digestvalue.
la firmo con estoy el documento xml .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Reference ref = fac.newReference
("", fac.newDigestMethod(DigestMethod.SHA1, null),
Collections.singletonList
(fac.newTransform
(Transform.ENVELOPED, (TransformParameterSpec) null)),
null, null);
// Create the SignedInfo.
SignedInfo si = fac.newSignedInfo
(fac.newCanonicalizationMethod
(CanonicalizationMethod.INCLUSIVE,
(C14NMethodParameterSpec) null),
fac.newSignatureMethod(SignatureMethod.RSA_SHA1, null),
Collections.singletonList(ref));
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream("mykeystore.jks"), "changeit".toCharArray());
KeyStore.PrivateKeyEntry keyEntry =
(KeyStore.PrivateKeyEntry) ks.getEntry
("mykey", new KeyStore.PasswordProtection("changeit".toCharArray()));
X509Certificate cert = (X509Certificate) keyEntry.getCertificate();
// Create the KeyInfo containing the X509Data.
KeyInfoFactory kif = fac.getKeyInfoFactory();
List x509Content = new ArrayList();
x509Content.add(cert.getSubjectX500Principal().getName());
x509Content.add(cert);
X509Data xd = kif.newX509Data(x509Content);
KeyInfo ki = kif.newKeyInfo(Collections.singletonList(xd));
// Instantiate the document to be signed.
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
Document doc = dbf.newDocumentBuilder().parse
(new FileInputStream("purchaseOrder.xml"));
// Create a DOMSignContext and specify the RSA PrivateKey and
// location of the resulting XMLSignature's parent element.
DOMSignContext dsc = new DOMSignContext
(keyEntry.getPrivateKey(), doc.getDocumentElement());
// Create the XMLSignature, but don't sign it yet.
XMLSignature signature = fac.newXMLSignature(si, ki);
//Generando la firma
signature.sign(dsc);
// y despues genero el documento xml pero me queda todo sin salto de linea.
OutputStream os = new FileOutputStream("signedPurchaseOrder.xml");
TransformerFactory tf = TransformerFactory.newInstance();
Transformer trans = tf.newTransformer();
trans.transform(new DOMSource(doc), new StreamResult(os));
Resultado
<LibroC xmlns="http://www.dddd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" xsi:schemaLocation="http://www.sd.xsd">
<EnvioLibro ID="ID201610">
<Hola><Hola>
</EnvioLibro> (Salto... pero despues no hay salto de linea en la etiqueta signature)
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><DigestValue>G0MRzIx+883NUS9IeyWuB+ST+O0=</DigestValue></Reference></SignedInfo><SignatureValue>W8Aofr6/ajWPj/frXQEnMCyoiA50N1KUMXTcBa1OHMzgf6OGJTobRYEWnaCffBPpCSis67VIVvzu
CGquJ4d2+pgRxCRneYAsVD+0gQEJM20mYJU7rN5GKpAQjELh5alwDEhseQMHsaGNTE5qQlrsHQDa
uTHvwKNdbKLEsUm4DL6BIyi6ymRJHGnNN2NBFw==</SignatureValue><KeyInfo><KeyValue><RSAKeyValue><Modulus>ppaEZipVitUq09iwFC4MXpbOSweZMhxvaMhej9Knib0ek+v9D8MU/t9u5duK0cZt0Qd7uLG5r4e7
fYPd++glqizW43IvN3TeWTIz6/dtZE7a9Ri9ae6xZxRkeutO/ZdcUBP8KJ0g+E23HEHbpGlXTByP
6nywdZH5oC0tnI5y2dRx8UqmRnXPCF5Aq2QyG+IAgLZ7CgWU3uj8BzCGALAraZaCneV6IGWupOkb
k7L8oPa7yM3/UCSKK3aq9tn95H4AvzDpUC+qaQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue><X509Data><X509Certificate>MIIGUjCCBTqgAwIBAgIIJklLQgmUzQ4wDQYJKoZIhvcNAQELBQAwga8xCzAJBgNVBAYTAkNMMRQw
EgYDVQQKDAtFLVNpZ24gUy5BLjE5MDcGA1UECwwwVGVybXMgb2YgdXNlIGF0IHd3dy5lc2lnbi1s
YS5jb20vYWN1ZXJkb3RlcmNlcm9zMSswKQYDVQQDDCJFLVNpZ24gQ2xhc3MgMiBGaXJtYSBUcmli
....
7bx2CcLBJ/EUDh4i8jBHkoq7D92dUY/En2s=</X509Certificate></X509Data></KeyInfo></Signature></LibroC>
Si alguien sabe como formatear el xml signature y que quede bien la firma.
He leido por todos lados y noo encuento una solución.
pls alguna ayuda..
Valora esta pregunta


0