PIX Ejemplo de firma estándar JWS y validación definida en el SPI (Sistema de Pago Instantáneo).
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";
byte[] signedJWS = api.signPIXJWS(strPrivKeyId,
header.getBytes("UTF-8"),
payload.getBytes("UTF-8"));
System.out.println(new String(signedJWS));
String strChainId = "key_chain";
boolean ret = api.checkPIXJWS(strChainId, null, signedJWS);
System.out.println("Assinatura ok: " + ret);
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.");
}
}