public interface SyncCrypto
| Modifier and Type | Method and Description |
|---|---|
void |
create_key()
Generates an asymmetric key pair (
RSA) in the Android Keystore. |
String |
decrypt(String cipherText)
Decrypt the text previously encrypted with
encrypt(String). |
String |
encrypt(String plainText)
Encrypt the plain text using an
AES key. |
boolean |
is_keystore_unlocked()
Check if the Android KeyStore is unlocked.
|
void |
unlock_keystore()
Launch the Android
Intent that will help define or unlock the KeyStore. |
String encrypt(String plainText) throws KeyStoreException
AES key.
The AES key is encrypted using an RSA (stored in the Android KeyStore) key then saved
along the encrypted text using a delimiter.
All operations require the KeyStore to be unlocked (authorized by the user authenticating with fingerprint/PIN/Pattern).plainText - text to encrypt.String of the encrypted text plus the encrypted AES used
to encrypt the text.KeyStoreException - for any encryption error.String decrypt(String cipherText) throws KeyStoreException
encrypt(String).
This will first extract the encrypted AES key, then decrypt it using
the previously generated RSA private key. The decrypted AES key will
be used tp decrypt the text.
All operations require the KeyStore to be unlocked (authorized by the user authenticating with fingerprint/PIN/Pattern).cipherText - encrypted text.KeyStoreException - for any decryption error.void create_key()
throws KeyStoreException
RSA) in the Android Keystore.
All operations require the KeyStore to be unlocked (authorized by the user authenticating with fingerprint/PIN/Pattern).KeyStoreException - for any KeyStore error.boolean is_keystore_unlocked()
throws KeyStoreException
true if the KeyStore is unlocked, false otherwise.KeyStoreException - for any KeyStore error.void unlock_keystore()
throws KeyStoreException
Intent that will help define or unlock the KeyStore.
Application are encouraged to check if the KeyStore is unlocked by overriding Activity.onResume()
when the user finishes defining unlocking the KeyStore or cancel and go bak to the application.
protected void onResume() {
super.onResume();
try {
// We return to the app after the KeyStore is unlocked or not.
if (cryptoClient.isKeystoreUnlocked()) {
// Encrypt/Decrypt
} else {
// Invite the user to unlock the KeyStore to continue
}
} catch (KeyStoreException e) {
e.printStackTrace();
}
}
KeyStoreException - for any KeyStore error.