DINAMO Networks is now aDINAMO cyber security company!
Java API
HSM DINAMO
Loading...
Searching...
No entry found
SignXML.java

Example of an XML signature with HSM.

See Note on examples.
package doxy.examples;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import com.dinamonetworks.Dinamo;
import br.com.trueaccess.TacNDJavaLib;
public class SignXML {
public static void main(String[] args) throws IOException {
String strAddr = "127.0.0.1";
String strUsrId = "master";
String strPwd = "12345678";
int nPort = 4433;
int nFlags = 0;
// Dados NFe
String strPrivKeyName ="nfe_key"; //Nome da chave no HSM
String strCertId ="nfe_cert"; //Nome do certificado no HSM
int nHashAlg = TacNDJavaLib.ALG_SHA2_256;
Path currentRelativePath = Paths.get("nfe.xml");
byte[] nfe = Files.readAllBytes(currentRelativePath);
byte[] filter = "http://www.portalfiscal.inf.br/nfe|infNFe|NFe11111111100000000002222222222223333333333333".getBytes();
Dinamo api = new Dinamo();
try {
api.openSession(strAddr, strUsrId, strPwd, nPort, nFlags);
byte[] signXMLNFE = api.signXML(strPrivKeyName, nHashAlg, strCertId, nfe, filter);
System.out.println(new String(signXMLNFE));
api.closeSession();
} catch (br.com.trueaccess.TacException e) {
e.printStackTrace();
}
System.out.println("Finalizado.");
}
}