Skip to content

Instantly share code, notes, and snippets.

@rozaydin
Created November 5, 2017 13:17
Show Gist options
  • Save rozaydin/d48c303c7869e4332362f8be0faab317 to your computer and use it in GitHub Desktop.
Save rozaydin/d48c303c7869e4332362f8be0faab317 to your computer and use it in GitHub Desktop.
Removed comments for clarity
@Test
public void JWTwithPaddingInBody() throws JoseException, org.jose4j.jwt.consumer.InvalidJwtException
{
String jwt_3 = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiIwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMSIsInN1YiI6IjAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxIiwiYXVkIjoiTWluZFNwaGVyZSBBUyIsImlhdCI6MTUwOTM1MjI5NywibmJmIjoxNTA5MzUyMjk3LCJleHAiOjE1MDk0Mzg2OTcsInNjaGVtYXMiOlsidXJuOnNpZW1lbnM6bWluZHNwaGVyZTp2MSJdLCJ0ZW4iOiJ0ZXN0LXRlbmFudCIsImp0aSI6IjkxODE3YTJkLTU0ZjQtNDQ1OC04YTI5LWU5MGU5ZDQ3YTViIn0=.G6U2GGJX0VCd6VW8-E4HnuvyRTNgct1oauornnOep_MMa8h-cDp8W6ca2LncYM2DaSpeVdO8haIuaAO3Z-vniDQqFa-__fZZvmDNex7D4YAFUqP5ZcW5wF9I3d73Y4uQ0uO07zBxbmZ4vCo6FtgtmwnyfY-BYV6Ag-ci0pw3ADD5uNEdrzL97Tcv500izRg09OuMIbppFkhVEwpWr1vl8Y-5_3gRfALLRBerc73Hcu-fcyXUJdOQTx-Qm3Ickr5bbNzcNsNUbhaNfI3Ij-dnM5IafdqsYbWKK7sbzhineOoldbn5Y0NqzdaHhUzKYjKhcB1sCDBG5E09z_HU00VNCjWCRFjAQTMvCHRUDKAoBOyhIufoKCLyh7zDfj5_OthX9DaCx_3Jg9hk2NcK-JjhN3QZTx2C38KB82YHFJNuUSd-K1I1WEBhfwebbhZPygKBv30OBUQ3V8DGmHDwyTUPMUFS-1CX5xEB4jSITQRyMeMsk3DPbhFjruHjMnkXIZq4";
Map<String, Object> publicKeyParts = new HashMap<>();
publicKeyParts.put("e", "AQAB");
publicKeyParts.put("n", "3JnqFea0WoCX58lt_AiiStZ8E8pslD_yQwSsxpgzUIWrhFQJffDYODvLG860_j8c_5pu7HHba2gnA6WlRuc9HQbXRv0fwezxh3q783DtUZQWB8Kwr1heAUIsahLjnxn6V82VsiEcQmxW_gP0Ucx6i6VKFH6xNVFu_ABVswms7I17v3Uo2QlMDIFPLbAaJ-NFqAHw3P0pnT8JLij4DVp0v-2Yn6Bd06uyHiXV4LLOHaEgwLVPIlkJL-vnWs85z1aNA_iPSt21PCfUu5v2z0j_-6eC-YmBR4DqPEqvthglbfxwtA9ZIcx2p1XwfBOwjoD2ItyppCa-Muo2_qgJH2HKZDbIbyziqUYK25eE6SkhZoA_UUywcK4WMJxgwCvGwVZs_BfqW9ddnSwqgIKAUlCU7JQwsijRTdmzbQHAoHoYvOX8vqmrobh-0FEITO2LkktqTpYIYdSqteOzXxLRt3sQ7tK-E6qbOOAqwiK0hRzvzMqYtO1NjFFpXxhqRoeczlrR");
RsaJsonWebKey rjwk = new RsaJsonWebKey(publicKeyParts);
RSAPublicKey publicKey = rjwk.getRsaPublicKey();
// although valid verification fails
JwtHelper.decodeAndVerify(jwt_3, new RsaVerifier(publicKey));
}
@Test
public void base64Test() {
String base64TestStr = "eyJpc3MiOiIwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMSIsInN1YiI6IjAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxIiwiYXVkIjoiTWluZFNwaGVyZSBBUyIsImlhdCI6MTUwOTM1MjI5NywibmJmIjoxNTA5MzUyMjk3LCJleHAiOjE1MDk0Mzg2OTcsInNjaGVtYXMiOlsidXJuOnNpZW1lbnM6bWluZHNwaGVyZTp2MSJdLCJ0ZW4iOiJ0ZXN0LXRlbmFudCIsImp0aSI6IjkxODE3YTJkLTU0ZjQtNDQ1OC04YTI5LWU5MGU5ZDQ3YTViIn0=";
String base64StrOutput = new String(org.springframework.security.jwt.codec.Codecs.b64UrlEncode(org.springframework.security.jwt.codec.Codecs.b64UrlDecode(base64TestStr)));
assertThat(base64StrOutput).isEqualTo(base64TestStr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment