Skip to content

Instantly share code, notes, and snippets.

@lordcodes
Created February 16, 2020 21:37
Show Gist options
  • Save lordcodes/d54ee75bcfee657021ca9185736a9280 to your computer and use it in GitHub Desktop.
Save lordcodes/d54ee75bcfee657021ca9185736a9280 to your computer and use it in GitHub Desktop.
Code for the article: "Protecting secrets in an Android project"
fun decrypt(encryptedData: ByteArray): String? {
val encryptionKey = generateKey()
val cell = SecureCell(encryptionKey, SecureCell.MODE_SEAL)
return try {
val cellData = SecureCellData(encryptedData, null)
val decodedData = cell.unprotect(encryptionContext, cellData)
String(decodedData)
} catch (error: SecureCellException) {
Log.e("EncryptionEngine", "Failed to decrypt message, error)
null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment