Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Decrypts the Storable instance using a passcode
* Decrypts the [Storable] instance using the [passcode].
* @pararm passcode the user's passcode
* @param storable the storable instance previously saved with [saveToPrefs]
* @return the raw byte key previously generated with [generateRandomKey]
fun getRawByteKey(passcode: CharArray, storable: Storable): ByteArray {
val aesWrappedKey = Base64.decode(storable.key, Base64.DEFAULT)
val iv = Base64.decode(storable.iv, Base64.DEFAULT)
val salt = Base64.decode(storable.salt, Base64.DEFAULT)
val secret: SecretKey = generateSecretKey(passcode, salt)
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
cipher.init(Cipher.DECRYPT_MODE, secret, IvParameterSpec(iv))
return cipher.doFinal(aesWrappedKey)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.