Created
October 29, 2016 10:00
-
-
Save flschweiger/fc0718bc2463a58f7a4fdad9d2354a1b to your computer and use it in GitHub Desktop.
Decrypt super secret message with authentication.
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
try { | |
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore"); | |
keyStore.load(null); | |
SecretKey secretKey = | |
(SecretKey) keyStore.getKey(SecurityConstants.KEY_AES, null); | |
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding"); | |
// The next line may throw a UserNotAuthenticatedException and | |
// we need to prompt the user to authenticate again | |
cipher.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(iv)); | |
byte[] decryptedBytes = cipher.doFinal(cipherBytes); | |
} catch (UserNotAuthenticatedException e) { | |
// User is not authenticated, let's authenticate with | |
// device credentials! | |
showAuthenticationScreen(); | |
return; | |
} catch { … } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment