Example of signature and verification using the PIX standard defined in SPI (Instant Payment System).
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;
public class SignVerifyPIX {
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\\pix\\pix.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.signPIX(strPrivKeyId,
strCertId,
xml);
System.out.println(new String(signedXml));
String strChainId = "key_chain";
boolean ret = api.verifyPIX(strChainId, null, signedXml);
System.out.println("Assinatura ok: " + ret);
api.closeSession();
} catch (br.com.trueaccess.TacException e) {
e.printStackTrace();
}
System.out.println("Finalizado.");
}
}