import org.jose4j.jwe.JsonWebEncryption;
import org.jose4j.jws.JsonWebSignature;
import org.jose4j.jwx.JsonWebStructure;
JsonWebEncryption jwe = null;
try {
jwe = (JsonWebEncryption) JsonWebStructure.fromCompactSerialization(integrityToken);
}catch (JoseException e){
e.printStackTrace();
}
Hello folks,
I'm trying to migrate play integrity at the backend side and I took this code part from https://developer.android.com/google/play/integrity/verdict#decrypt-verify-locally. . In this code I get this exception :
Exception in thread "main" java.lang.ClassCastException: class org.jose4j.jws.JsonWebSignature cannot be cast to class org.jose4j.jwe.JsonWebEncryption (org.jose4j.jws.JsonWebSignature and org.jose4j.jwe.JsonWebEncryption are in unnamed module of loader 'app')
As you can see below fromCompactSerialization method returns JsonWebStructure type and it causes casting error.
public static JsonWebStructure fromCompactSerialization(String cs) throws JoseException {
String[] parts = CompactSerializer.deserialize(cs);
Object jsonWebObject;
if (parts.length == 5) {
jsonWebObject = new JsonWebEncryption();
} else {
if (parts.length != 3) {
throw new JoseException("Invalid JOSE Compact Serialization. Expecting either 3 or 5 parts for JWS or JWE respectively but was " + parts.length + ".");
}
jsonWebObject = new JsonWebSignature();
}
((JsonWebStructure)jsonWebObject).setCompactSerializationParts(parts);
((JsonWebStructure)jsonWebObject).rawCompactSerialization = cs;
return (JsonWebStructure)jsonWebObject;
}
Do you have any idea how can I cast JsonWebStructure object to JsonWebEncryption object in java?