I have a room Entity where I want to simply obfuscate a string field before saving to database.
@Entity
data class User(
@PrimaryKey
val uid: Int,
@ColumnInfo(name = "first_name")
val firstName: String,
@ColumnInfo(name = "last_name")
val lastName: String
)
So the idea is that when I save an object with lastName="Doe", I want to do some processing at my side and the output to be saved to the database.. So something like a TypeConverter.
so a basic typeconverter
class Converters {
@TypeConverter
fun fromLastName(value: String): String {
return value.reversed()
}
@TypeConverter
fun toLastName(value: String): String {
return value.reversed()
}
}
so basically I am trying to achieve is to just obfuscate a field, I dont need SqlCypher here because it increases the app size and much work is needed to keep the passphrase secure and this is just to hide the actual value of a field (which is not sensitive, still some one can use it to harvest data from the api) from the user who peeps into the database.
I know I can create the lastName as another data class and serialize with type converter but the same class is reused for api requests and almost all data model thing so can't find a way. Is there a simple way I can make this happen?
from Android Room TypeConverter like logic for a specific primitive field
No comments:
Post a Comment