Java API
HSM Dinamo
Loading...
Looking for...
No entries found
SignVerifyPIX.java

Example of signature and verification using the PIX standard defined in SPI (Instant Payment System).

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;
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"; //Nome da chave no HSM
String strCertId ="key_cert"; //Nome do certificado no HSM
byte[] signedXml = api.signPIX(strPrivKeyId,
strCertId,
xml);
System.out.println(new String(signedXml));
String strChainId = "key_chain"; //Nome da cadeia de certificados no HSM
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.");
}
}