fernet-java8
fernet-java8 copied to clipboard
Getting crash in 5, 6, and 7 android version
Based on discussion on this #https://github.com/l0s/fernet-java8/issues/377 I changed my code to be like this :
val keyByte = Base64.decode(keyString, Base64.URL_SAFE)
val key = Key(keyByte)
val tokenByte = Base64.decode(encrypted, Base64.URL_SAFE)
val token = Token.fromBytes(tokenByte)
val validator: Validator<String> = object : StringValidator {
override fun getTimeToLive(): TemporalAmount {
return Duration.ofHours(1)
}
}
target = token.validateAndDecrypt(key, validator)
but the crash still happening
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/util/Base64;
at com.macasaet.fernet.Constants.<clinit>(Constants.java:37)
at com.macasaet.fernet.StringValidator$-CC.$default$getCharset(StringValidator.java:36)
at com.julofinance.juloapp.utils.Utils2$decryptFernetEncryption$validator$1.getCharset(Utils2.kt)
at com.macasaet.fernet.StringValidator$-CC.lambda$getTransformer$0(StringValidator.java:41)
at com.macasaet.fernet.-$$Lambda$StringValidator$gDRwV6XvTN55-2t20AK2HDVrFfY.apply(lambda)
at com.macasaet.fernet.Validator$-CC.$default$validateAndDecrypt(Validator.java:105)
at com.julofinance.juloapp.utils.Utils2$decryptFernetEncryption$validator$1.validateAndDecrypt(Utils2.kt)
at com.macasaet.fernet.Token.validateAndDecrypt(Token.java:228)
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.util.Base64" on path: DexPathList[[zip file "/data/app/com.julofinance.juloapp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.julofinance.juloapp-2/lib/x86, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.macasaet.fernet.Constants.<clinit>(Constants.java:37)
at com.macasaet.fernet.StringValidator$-CC.$default$getCharset(StringValidator.java:36)
at com.julofinance.juloapp.utils.Utils2$decryptFernetEncryption$validator$1.getCharset(Utils2.kt)
at com.macasaet.fernet.StringValidator$-CC.lambda$getTransformer$0(StringValidator.java:41)
at com.macasaet.fernet.-$$Lambda$StringValidator$gDRwV6XvTN55-2t20AK2HDVrFfY.apply(lambda)
at com.macasaet.fernet.Validator$-CC.$default$validateAndDecrypt(Validator.java:105)
at com.julofinance.juloapp.utils.Utils2$decryptFernetEncryption$validator$1.validateAndDecrypt(Utils2.kt)
at com.macasaet.fernet.Token.validateAndDecrypt(Token.java:228)
please help
@luckysenjaya do you have a full sample Android project that reproduces this issue? I tried to create a simple "hello world" app that generates then decrypts a token, but I am not able to reproduce that error.
As an aside, are you using ProGuard to minify the APK? It should remove any unused fields like the Java 8 encoders.
Here is an example based on the Fernet test vector and the default "Hello World" from Android Studio:
val key = Key(
Base64.decode(
"cw_0x689RpI-jtRR7oE8h_eQsKImvJapLeSbXpwF4e4=",
Base64.URL_SAFE
)
)
val token = Token.fromBytes(
Base64.decode(
"gAAAAAAdwJ6wAAECAwQFBgcICQoLDA0ODy021cpGVWKZ_eEwCGM4BLLF_5CV9dOPmrhuVUPgJobwOz7JcbmrR64jVmpU4IwqDA==",
Base64.URL_SAFE
)
)
val validator: Validator<String> = object : StringValidator {
@RequiresApi(Build.VERSION_CODES.O)
override fun getClock(): Clock {
return Clock.fixed(
Year.of(1985).atMonth(10).atDay(26)
.atTime(1, 20, 1)
.atZone(ZoneOffset.ofHours(-7))
.toInstant(),
ZoneOffset.ofHours(-7)
)
}
}
val textView = findViewById<TextView>(R.id.textView)
textView.text = token.validateAndDecrypt(key, validator)