[JWE] AndroidKeyStoreRSAPrivateKey cannot be cast to RSAPrivateKey

Issue #123 closed
Daniel Łojewski created an issue

Hi,

I encountered issue during decryption of the jwe payload on Android 6.0+

org.jose4j.lang.InvalidKeyException: Invalid key java.lang.ClassCastException: Cannot cast android.security.keystore.AndroidKeyStoreRSAPrivateKey to java.security.interfaces.RSAPrivateKey
        at org.jose4j.jwx.KeyValidationSupport.castKey(KeyValidationSupport.java:64)
        at org.jose4j.jwe.RsaKeyManagementAlgorithm.validateDecryptionKey(RsaKeyManagementAlgorithm.java:59)
        at org.jose4j.jwe.JsonWebEncryption.decrypt(JsonWebEncryption.java:202)
        at org.jose4j.jwe.JsonWebEncryption.getPlaintextBytes(JsonWebEncryption.java:79)
        at org.jose4j.jwe.JsonWebEncryption.getPlaintextString(JsonWebEncryption.java:72)
        at org.jose4j.jwe.JsonWebEncryption.getPayload(JsonWebEncryption.java:87)

It's similar to jws problem encountered while ago. https://bitbucket.org/b_c/jose4j/pull-requests/8/fix-for-android-60-marshmallow/diff

I'm not sure if similiar fix will work in here as well since RSAKey != RSAPrivateKey.

Workaround suggested in the linked pull request with setDoKeyValidation(false) does the job hence low priority ;)

jose4j v.0.6.4

Comments (3)

  1. Brian Campbell repo owner

    I'll try and look into what, if anything, can be done cleanly to make it work without resorting to setDoKeyValidation(false). Glad the workaround works though! And yeah, low priority ;)

  2. Log in to comment