java-jwt
java-jwt copied to clipboard
Can't validate token on Android (Java version?)
My code:
public static Token decodeFromJWT(String rawJwt, String pemFileStr) throws Exception {
Reader rdr = new StringReader(pemFileStr);
org.bouncycastle.util.io.pem.PemObject pemObject = new org.bouncycastle.util.io.pem.PemReader(rdr).readPemObject();
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(pemObject.getContent());
Security.addProvider(new BouncyCastleProvider());
KeyFactory kf = KeyFactory.getInstance("RSA", BouncyCastleProvider.PROVIDER_NAME);
PublicKey key = kf.generatePublic(keySpec);
Algorithm algorithm = Algorithm.RSA512((RSAPublicKey) key, null);
JWTVerifier verifier = JWT.require(algorithm)
.withIssuer("XXX")
.withAudience("XXX")
.build();
DecodedJWT jwt = verifier.verify(rawJwt);//throws exception
//some code here
}
Unable to load JDK7 types (annotations, java.nio.file.Path): no Java7 support added (...) Caused by: java.lang.NoSuchMethodError: No static method decodeBase64(Ljava/lang/String;)[B in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boot.jar)
Apache commons doesn't work well on Android that's why you receive the exception. If you only need to decode the tokens we provide a library for that, but verification is not possible.