Closed rodrixan closed 6 years ago
i think it throwing a IllegalBlockSizeException
for long string values.
Hi @rodrixan & @oikmar ,
We are aware of this limitation to max 245 characters. That is a flaw of Assymmetric Encryption and unfortunately we can't do much about that.
We are currently working on an implementation of secure storage that uses Symmetric Encryption which does not have these kind of limitations.
Came across the same problem and done a workaround.
Until the new release is ready, you can use this:
object SecurePreferencesHelper {
private const val chunkSize = 240
private fun getNumberOfChunksKey(key: String) = "${key}_numberOfChunks"
fun setLongStringValue(key: String, value: String) {
val chunks = value.chunked(chunkSize)
SecurePreferences.setValue(getNumberOfChunksKey(key), chunks.size)
chunks.forEachIndexed { index, chunk ->
SecurePreferences.setValue("$key$index", chunk)
}
}
fun getLongStringValue(key: String): String? {
val numberOfChunks = SecurePreferences.getIntValue(getNumberOfChunksKey(key), 0)
if (numberOfChunks == 0) {
return null
}
return (0 until numberOfChunks)
.map { index ->
val string = SecurePreferences.getStringValue("$key$index", null) ?: run {
return null
}
string
}.reduce { accumulator, chunk -> accumulator + chunk }
}
fun removeLongStringValue(key: String) {
val numberOfChunks = SecurePreferences.getIntValue(getNumberOfChunksKey(key), 0)
(0 until numberOfChunks).map { SecurePreferences.removeValue("$key$it") }
SecurePreferences.removeValue(getNumberOfChunksKey(key))
}
fun containsLongStringValue(key: String): Boolean {
return SecurePreferences.contains(getNumberOfChunksKey(key))
}
}
Was about to abandon the library due to this limit- happy to see a workaround + plans for having this in the next release. Clever!
i don't think this works any longer :/
i've updated the workaround against 1.2.2 https://github.com/exozet/AndroidCore/blob/master/core/src/main/java/com/exozet/android/core/storage/SecurePreferencesLongString.kt
also relevant:
usage:
var password by secureStorage("password", "")
password = jwt
Hi there!
First of all, awesome job on the library, it really keeps the encrypting neat and simple. Good work!
Nevertheless, I'm facing the next issue: When a long string is gonna be stored, the library throws an Exception (see below for more info). It seems to happen when the string length is over 245 characters.
As long as I've not been able to see anything related to this in the documentation, Is it supposed to work like that?
Furthermore, if any user wants to store a token from backend or something similar, what can he do as an alternative?
Thanks in advice, and greetings,
Rodri