1. Primero generar la Cadena Original.
Source xsltSource = new StreamSource(prop.getProperty("DOCROOT") + "cadena_original3.xsl");
StreamSource source2 = new StreamSource(prop.getProperty("DOCROOT") + "facturaCFDI" + numeroComprobante + ".xml");
StreamResult result2 = new StreamResult(prop.getProperty("DOCROOT") + "cadena" + numeroComprobante + ".xml");
TransformerFactory tFactory = TransformerFactory.newInstance();
javax.xml.transform.Transformer transformer2 = tFactory.newTransformer(xsltSource);
transformer2.transform(source2, result2);
2.- Generar el Sello Digital de la cadena Original.
try {
String cadenaOriginal = getCadenaOriginal();
String selloDigital = null;
PKCS8Key pkcs8 = null;
try {
pkcs8 = new PKCS8Key(clavePrivada, clave.toCharArray());
} catch (GeneralSecurityException ex) {
Logger.getLogger(CID.class.getName()).log(Level.SEVERE, null, ex);
}
PrivateKey pk = pkcs8.getPrivateKey();
Signature firma = Signature.getInstance("SHA1withRSA");
try {
firma.initSign(pk);
} catch (InvalidKeyException ex) {
Logger.getLogger(CID.class.getName()).log(Level.SEVERE, null, ex);
}
try {
firma.update(cadenaOriginal.getBytes("UTF-8"));
BASE64Encoder b64 = new BASE64Encoder();
selloDigital = b64.encode(firma.sign());
char caracter = 10;
selloDigital = selloDigital.replaceAll(caracter + "", "");
} catch (SignatureException ex) {
Logger.getLogger(CID.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedEncodingException e) {
}
// falta sellar el comprobante comprobante.setSello(selloDigital);
fijarComprobante("sello", selloDigital);
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(CID.class.getName()).log(Level.SEVERE, null, ex);
}
3.- Timbar el Servicio
TimbradoServiceService service = new TimbradoServiceService();
TimbradoService port = service.getTimbradoServicePort();
return port.timbrado(cfdi, usuario, contraseƱa);
No comments:
Post a Comment