Android Question Using keystore for storing sensitive data

iCAB

Well-Known Member
Licensed User
Longtime User
B4X: Copy
   ks.encryptString(alias,strtoencrypt)

End Sub
Sub KeyStore_Encrypted(encrypted() As Byte, iv() As Byte, base64 As String)
    Log($"KeyStore_Encrypted(${base64},${encrypted.Length},${iv.Length})"$)
    ' Note to save the iv array to later be able to Decrypt!
    Log($"Decrypt using the IV"$)
    Dim decrypted As String = ks.decryptString("DonManfred",base64,iv)
    Log($"Decrypted: ${decrypted}"$)
    
End Sub
 
Upvote 0
Hi Don

Thanks for your reply.
Sorry still not clear :(

1. Does this encrypt the string? and if so how to capture the returned value?
B4X: Copy
 ks.encryptString(alias,strtoencrypt)

2. I don't see this function being called anywhere in the sample code
B4X: Copy
Sub KeyStore_Encrypted(encrypted() As Byte, iv() As Byte, base64 As String)
and when called, what values should be provided in enctypted() & iv()

Thanks
iCAB
 
Upvote 0
2. I don't see this function being called anywhere in the sample code
It is an Event which is raised when the encryption is ready.
and when called, what values should be provided in enctypted() & iv()
The values are FILLED in the Event.

It is a Event which is raised because i need to return multiple values; not only the encrypted string.
In the event you get the encrypted string AND the iv Vector.

' Note to save the iv array to later be able to Decrypt!
 
Upvote 0
One more question please

Are we supposed to store "base64" securely in the keystore or is it ok to store it anywhere at this point?
 
Upvote 0
Back
Top