public class SyncCryptoLegacy extends Object implements SyncCrypto
SyncCrypto methods for API 9 to 18 (pre Android KeyStore public API).| Constructor and Description |
|---|
SyncCryptoLegacy(android.content.Context context) |
| 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
SyncCrypto.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. |
public SyncCryptoLegacy(android.content.Context context)
throws KeyStoreException
KeyStoreExceptionpublic String encrypt(String plainText) throws KeyStoreException
SyncCryptoAES 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).encrypt in interface SyncCryptoplainText - text to encrypt.String of the encrypted text plus the encrypted AES used
to encrypt the text.KeyStoreException - for any encryption error.public String decrypt(String cipherText) throws KeyStoreException
SyncCryptoSyncCrypto.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).decrypt in interface SyncCryptocipherText - encrypted text.KeyStoreException - for any decryption error.public boolean is_keystore_unlocked()
throws KeyStoreException
SyncCryptois_keystore_unlocked in interface SyncCryptotrue if the KeyStore is unlocked, false otherwise.KeyStoreException - for any KeyStore error.public void unlock_keystore()
throws KeyStoreException
SyncCryptoIntent 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();
}
}
unlock_keystore in interface SyncCryptoKeyStoreException - for any KeyStore error.public void create_key()
throws KeyStoreException
SyncCryptoRSA) in the Android Keystore.
All operations require the KeyStore to be unlocked (authorized by the user authenticating with fingerprint/PIN/Pattern).create_key in interface SyncCryptoKeyStoreException - for any KeyStore error.