Last active
April 1, 2018 21:12
-
-
Save yakivmospan/12227efe4dad6aaa2601fa51fd0c14bf to your computer and use it in GitHub Desktop.
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
val message = "Very large message, bigger then 250 symblos..." | |
// Simple Shared Preferences wrapper, will be used to save wrapped key | |
val storage = Storage(context) | |
// Creates Android Key Store and provides manage functions | |
val keyStoreWrapper = KeyStoreWrapper(context) | |
// Create and Save asymmetric key | |
keyStoreWrapper.createAndroidKeyStoreSymmetricKey("MASTER_KEY") | |
// Get key from keyStore | |
val masterKey = keyStoreWrapper.getAndroidKeyStoreSymmetricKey("MASTER_KEY") | |
// Creates Cipher with symmetric transformation and provides encrypt and decrypt functions | |
val cipher = CipherWrapper("AES/CBC/PKCS7Padding") | |
// Encrypt message with IV | |
val encryptedMessage = cipher.encrypt(message, masterKey, useInitializationVector = true) | |
// Decrypt message with IV | |
val decryptedMessage = cipher.decrypt(encryptedMessage, masterKey, useInitializationVector = true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment