Java API
HSM Dinamo
Loading...
Looking for...
No entries 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"; //Name of key in HSM
String strCertId ="nfe_cert"; //Name of certificate in 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("Finished.");
}
}