RFC 7797 JWS Unencoded Payload doesn't work.

Issue #339 closed
Yaroslav Soltys created an issue

I need to generate jws with an unencoded payload according to RFC 7797.

I’ve written code according to your wiki tutorial:

public static String createJwsSignature() throws CertificateException, UnrecoverableEntryException, NoSuchAlgorithmException, KeyStoreException, IOException, JoseException {
    JsonWebSignature signerJws = new JsonWebSignature();
    signerJws.setPayload("{\"key\": \"value\"}");

    signerJws.getHeaders().setObjectHeaderValue(HeaderParameterNames.BASE64URL_ENCODE_PAYLOAD, false);

    signerJws.setCriticalHeaderNames(
            HeaderParameterNames.BASE64URL_ENCODE_PAYLOAD
    );
    signerJws.setKeyIdHeaderValue("213081410402036757863450612430055725658");
    signerJws.setAlgorithmHeaderValue("RS256");

    signerJws.setKey(HttpClientUtil.getPrivateKey());

   return signerJws.getCompactSerialization();
}

And it generates me a jws with an encoded payload :

eyJiNjQiOmZhbHNlLCJjcml0IjpbImI2NCJdLCJraWQiOiIyMTMwODE0MTA0MDIwMzY3NTc4NjM0NTA2MTI0MzAwNTU3MjU2NTgiLCJhbGciOiJSUzI1NiJ9.eyJrZXkiOiAidmFsdWUifQ.T0MV9G55LQyEDLRO_Q2XXYXOFqkUaoxvHfneyH5iqq2i9ba-ThPePPx3JdgkGIrthyDBjNPGr8REF0mPcO_knPBO1sMv6vr1LIr4kVmVg5ougQ6oi7V6QZ1WnHYWE94BfJHu_r0SJ0OGnoQPGDqXLKL3PttXeXbE7Xe9MiaJYOfKEw9bHX-0lxCEJjphYhZS8uWA2DmqqLrs9to8OdT1eau92HveLzux7X1r4jPxzkgeN6fGqUv_Oyd6lfWJPEu_ZDGXUAZSRM7QI9ok1oGf8jbmIECTGrc4Wv0D1ocE1uObUSt2tDmQ-GgLGXa8DwlXqS0AZBI6GeZOkotTEYYiXw

When I call signerJws.toString() It get me correct header structure but anyway payload is encoded in the final jws.

JsonWebSignature{"b64":false,"crit":["b64"],"kid":"213081410402036757863450612430055725658","alg":"RS256"}

Comments (2)

  1. Log in to comment