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

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

See Note on examples.
package doxy.examples;
import java.io.IOException;
import com.dinamonetworks.Dinamo;
import com.dinamonetworks.JwsComponents;
public class SignVerifyPIXJWS {
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 header = "{\"alg\":\"RS256\"}";
String payload = "{\"iss\":\"joe\"," +
"\"exp\":1300819380," +
"\"http://example.com/is_root\":true}";
Dinamo api = new Dinamo();
try {
api.openSession(strAddr, strUsrId, strPwd, nPort, nFlags);
System.out.println("Connected.");
String strPrivKeyId = "key"; //Name of key in HSM
byte[] signedJWS = api.signPIXJWS(strPrivKeyId,
header.getBytes("UTF-8"),
payload.getBytes("UTF-8"));
System.out.println(new String(signedJWS));
String strChainId = "key_chain"; //Name of the certificate chain in the HSM
//Opção 1 de validação de assinatura PIX JWS
boolean ret = api.checkPIXJWS(strChainId, null, signedJWS);
System.out.println("Signature ok: " + ret);
//Opção 2 de validação de assinatura PIX JWS
JwsComponents jwsComponents = api.checkPIXJWS(strChainId, null, signedJWS, 0);
System.out.println("Header: " + new String(jwsComponents.getHeader());
System.out.println("Payload: " + new String(jwsComponents.getPayload());
System.out.println("Return Code: " + jwsComponents.getRet_code());
System.out.println("Signature ok: " + (jwsComponents.getRet_code() == 0));
api.closeSession();
} catch (br.com.trueaccess.TacException e) {
e.printStackTrace();
}
System.out.println("Finished.");
}
}