in app/src/main/java/com/epam/securestorage/providers/cipher/CipherEncryptionProvider.java [193:227]
public String get(@NonNull String key) {
if (key == null || key.isEmpty()) {
if (callback != null) {
callback.onError(GET, new SecureStorageException("Key or Value can't be NULL ot empty"));
}
return null;
}
key = generateKeyWithPrefix(key);
KeyStore.PrivateKeyEntry privateKeyEntry;
try {
privateKeyEntry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(KEY_ALIAS, null);
if (privateKeyEntry == null) return null;
Cipher cipher = Cipher.getInstance(CIPHER_TYPE, CIPHER_PROVIDER);
cipher.init(Cipher.DECRYPT_MODE, privateKeyEntry.getPrivateKey());
String value = getPref(key);
if (value.isEmpty()) return null;
byte[] bytes = getBytes(cipher, value);
String result = new String(bytes, StandardCharsets.UTF_8);
if (callback != null) {
callback.onComplete(GET);
}
return result;
} catch (NoSuchAlgorithmException | KeyStoreException | InvalidKeyException | IOException | NoSuchPaddingException | UnrecoverableEntryException | NoSuchProviderException e) {
e.printStackTrace();
if (callback != null) {
callback.onError(GET, e);
}
return null;
}
}