This file contains 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 spec = KeyGenParameterSpec.Builder( | |
KEY_NAME, | |
KeyProperties.PURPOSE_ENCRYPT or | |
KeyProperties.PURPOSE_DECRYPT | |
).apply { | |
setBlockModes(KeyProperties.BLOCK_MODE_CBC) | |
setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7) | |
setUserAuthenticationRequired(true) | |
setUserAuthenticationValidityDurationSeconds(TIMEOUT_SECONDS) | |
setRandomizedEncryptionRequired(false) |
This file contains 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
biometricPrompt.authenticate(promptInfo) |
This file contains 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
var biometricPrompt = BiometricPrompt(this, executor, object : BiometricPrompt.AuthenticationCallback() { | |
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) { | |
super.onAuthenticationError(errorCode, errString) | |
// Error | |
} | |
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) { | |
super.onAuthenticationSucceeded(result) | |
// Success | |
} |
This file contains 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 biometricPromptBuilder = BiometricPrompt.PromptInfo.Builder() | |
.setTitle("A nice title") | |
.setSubtitle("A nicer subtitle") | |
.setNegativeButtonText("Cancel") | |
.build() |
This file contains 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
//Write to file | |
encryptedFile.openFileOutput().bufferedWriter().use { | |
it.write("Hola Mexico! vamos a encriptar esto") | |
} | |
//Read from file | |
val contents = encryptedFile.bufferedReader().useLines { lines -> | |
lines.fold("") { working, line -> | |
"$working\n$line" | |
} |
This file contains 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 encryptedFile = EncryptedFile.Builder( | |
File(directoryPath, "FileName"), | |
context, | |
masterKeyAlias, | |
EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB | |
).build() |
This file contains 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
KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA, "AndroidKeyStore").apply { | |
val certBuilder = KeyGenParameterSpec.Builder(alias, KeyProperties.PURPOSE_ENCRYPT) | |
.setKeyValidityStart(keyValidityStart) | |
.setKeyValidityEnd(keyValidityEnd) | |
.setCertificateSerialNumber(BigInteger.valueOf(1L)) | |
.setCertificateSubject(X500Principal("CN=MyCompany")) | |
.setUserAuthenticationRequired(true) | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | |
initialize( | |
certBuilder |
This file contains 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
// Release Candidate option | |
val keyGenParameterSpec = MasterKeys.AES256_GCM_SPEC | |
val masterKeyAlias = MasterKeys.getOrCreate(keyGenParameterSpec) | |
// Alpha option | |
val masterKeyAvailable = MasterKey | |
.Builder(application.applicationContext) | |
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM) | |
.build() |
NewerOlder