Exemplo de assinatura XML com o HSM.
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;
String strPrivKeyName ="nfe_key";
String strCertId ="nfe_cert";
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.");
}
}