SignXML.java

Exemplo de assinatura XML com o HSM.

Veja Nota sobre os exemplos.
package doxy.examples;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class SignXML {
public static void main(String[] args) throws IOException {
String strAddr = "10.0.0.2";
String strUsrId = "usuario";
String strPwd = "senha";
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.");
}
}