API Java
HSM Dinamo
Cargando...
Buscando...
No se han encontrado entradas
SignVerifyPIXJWS.java

PIX Ejemplo de firma estándar JWS y validación definida en el SPI (Sistema de Pago Instantáneo).

Véase la nota sobre ejemplos.
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("Conectado.");
String strPrivKeyId = "key"; //Nome da chave no HSM
byte[] signedJWS = api.signPIXJWS(strPrivKeyId,
header.getBytes("UTF-8"),
payload.getBytes("UTF-8"));
System.out.println(new String(signedJWS));
String strChainId = "key_chain"; //Nome da cadeia de certificados no HSM
//Opção 1 de validação de assinatura PIX JWS
boolean ret = api.checkPIXJWS(strChainId, null, signedJWS);
System.out.println("Assinatura 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("Assinatura ok: " + (jwsComponents.getRet_code() == 0));
api.closeSession();
} catch (br.com.trueaccess.TacException e) {
e.printStackTrace();
}
System.out.println("Finalizado.");
}
}