Created
February 16, 2020 21:37
-
-
Save lordcodes/d54ee75bcfee657021ca9185736a9280 to your computer and use it in GitHub Desktop.
Code for the article: "Protecting secrets in an Android project"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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