Skip to content

Instantly share code, notes, and snippets.

@yakivmospan
Last active April 1, 2018 21:12
Show Gist options
  • Save yakivmospan/12227efe4dad6aaa2601fa51fd0c14bf to your computer and use it in GitHub Desktop.
Save yakivmospan/12227efe4dad6aaa2601fa51fd0c14bf to your computer and use it in GitHub Desktop.
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