"VlZjMxNGJjNzAzNyJ9" +
"." +
"." +
"s0h6KThzkfBBBkLspW1h84VsJZFTsPPqMDA7g1Md7p0";
JsonWebSignature jws = new JsonWebSignature();
jws.setCompactSerialization(detachedCs);
JsonWebKey jwk = JsonWebKey.Factory.newJwk(jwkJsonString);
jws.setKey(jwk.getKey());
jws.setEncodedPayload(encodedJwsPayload);
assertThat(jws.verifySignature(), is(true));
assertThat(jws.getPayload(), equalTo(jwsPayload));
// verify reproducing it (it's just luck that using the setters for the headers results in the exact same
// JSON representation of the header)
jws = new JsonWebSignature();
jws.setPayload(jwsPayload);
jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.HMAC_SHA256);
jws.setKeyIdHeaderValue(jwk.getKeyId());
jws.setKey(jwk.getKey());
// To create a detached signature, sign and then concatenate the encoded header, two dots "..", and the encoded signature
jws.sign();
String encodedHeader = jws.getHeaders().getEncodedHeader();
String encodedSignature = jws.getEncodedSignature();
String reproducedDetachedCs = encodedHeader + ".." + encodedSignature;
assertThat(detachedCs, is(equalTo(reproducedDetachedCs)));
assertThat(encodedJwsPayload, is(equalTo(jws.getEncodedPayload())));
}