Problem with IV in Android Device
I'm trying to do a little test in Android devices, first I implement the test as Unit Test executing it in local machine (JVM 1.8). It works fine.
Later I try to execute the same test as Android Test in a physical device the result is:
com.nimbusds.jose.JOSEException: unknown parameter spec passed to IV parameters object. at com.nimbusds.jose.crypto.AESGCM.actualParamsOf(AESGCM.java:240) at com.nimbusds.jose.crypto.AESGCM.actualIVOf(AESGCM.java:173) at com.nimbusds.jose.crypto.AESGCM.encrypt(AESGCM.java:149) at com.nimbusds.jose.crypto.ContentCryptoProvider.encrypt(ContentCryptoProvider.java:187) at com.nimbusds.jose.crypto.DirectEncrypter.encrypt(DirectEncrypter.java:141) at com.nimbusds.jose.JWEObject.encrypt(JWEObject.java:370) at com.bankinter.bkwallet.data.remote.EncryptionUtils.encryptJWEToServer(EncryptionUtils.java:38) at com.bankinter.bkwallet.data.local.EncryptionUtilsTest.jweEncryptAndDecryptTest(EncryptionUtilsTest.java:33) at java.lang.reflect.Method.invoke(Native Method) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at org.junit.runner.JUnitCore.run(JUnitCore.java:115) at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59) at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1879) Caused by: java.security.spec.InvalidParameterSpecException: unknown parameter spec passed to IV parameters object. at com.android.org.bouncycastle.jcajce.provider.symmetric.util.IvAlgorithmParameters.localEngineGetParameterSpec(IvAlgorithmParameters.java:51) at com.android.org.bouncycastle.jcajce.provider.symmetric.util.BaseAlgorithmParameters.engineGetParameterSpec(BaseAlgorithmParameters.java:24) at java.security.AlgorithmParameters.getParameterSpec(AlgorithmParameters.java:257) at com.nimbusds.jose.crypto.AESGCM.actualParamsOf(AESGCM.java:238) ... 35 more
The code:
public static String encryptJWEToServer(String originalData, SecretKey key) throws Exception{ JWEHeader header = new JWEHeader.Builder(JWEAlgorithm.DIR, EncryptionMethod.A256GCM) .build();
Payload payload = new Payload(originalData);
JWEObject jweObject = new JWEObject(header, payload);
DirectEncrypter directEncrypter = new DirectEncrypter(key);
jweObject.encrypt(directEncrypter);
return jweObject.serialize();
}
Comments (3)
-
-
Forget it, I could solve it with part of other response (https://bitbucket.org/connect2id/nimbus-jose-jwt/issues/185/android-comnimbusdsjosejoseexception).
I only need to set the provider for the DirectEncrypter like this:
directEncrypter.getJCAContext().setProvider(com.nimbusds.jose.crypto.bc.BouncyCastleProviderSingleton.getInstance());
You can close this issue.
Thank you very much.
-
- changed status to invalid
Closing as invalid / solved.
Older versions of Java and Android don't support AES/GCM encryption, so yes, switching the BouncyCastle crypto provider is (one) solution.
- Log in to comment
Sorry for the anonymous. If you need more data tell me.