fix crash on initial launch

This commit is contained in:
Phillip Thelen 2019-06-20 10:01:50 +02:00
parent d9f9d4b7da
commit 23484e1e09
2 changed files with 11 additions and 5 deletions

View file

@ -150,7 +150,7 @@ android {
buildConfigField "String", "TESTING_LEVEL", "\"production\""
multiDexEnabled true
versionCode 2161
versionCode 2165
versionName "1.10"
}

View file

@ -159,7 +159,7 @@ constructor(ctx: Context, var sharedPreferences: SharedPreferences, var keyStore
@Throws(NoSuchAlgorithmException::class, NoSuchPaddingException::class, NoSuchProviderException::class, BadPaddingException::class, IllegalBlockSizeException::class, UnsupportedEncodingException::class)
fun decrypt(encrypted: String): String {
fun decrypt(encrypted: String): String? {
val c: Cipher
val publicIV = getRandomIV()
@ -180,9 +180,15 @@ constructor(ctx: Context, var sharedPreferences: SharedPreferences, var keyStore
}
val decodedValue = Base64.decode(encrypted.toByteArray(charset("UTF-8")), Base64.DEFAULT)
val decryptedVal = c.doFinal(decodedValue)
return String(decryptedVal)
return try {
val decodedValue = Base64.decode(encrypted.toByteArray(charset("UTF-8")), Base64.DEFAULT)
val decryptedVal = c.doFinal(decodedValue)
String(decryptedVal)
} catch (error: IllegalArgumentException) {
null
} catch (e: GeneralSecurityException) {
null
}
}
private fun getRandomIV(): String {