Ejemplo de firma y verificación mediante la norma DICT definida en el SPI (Sistema de Pago Instantáneo).
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 SignVerifyPIXDict {
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;
Path currentRelativePath = Paths.get("c:\\tmp\\dict.xml");
byte[] xml = Files.readAllBytes(currentRelativePath);
Dinamo api = new Dinamo();
try {
api.openSession(strAddr, strUsrId, strPwd, nPort, nFlags);
System.out.println("Conectado.");
String strPrivKeyId ="key";
String strCertId ="key_cert";
byte[] signedXml = api.signPIXDict(strPrivKeyId,
strCertId,
xml);
System.out.println(new String(signedXml));
String strChainId = "key_chain";
boolean ret = api.verifyPIXDict(strChainId, null, signedXml);
System.out.println("Assinatura ok: " + ret);
api.closeSession();
} catch (br.com.trueaccess.TacException e) {
e.printStackTrace();
}
System.out.println("Finalizado.");
}
}