in app/src/main/java/com/epam/securestorage/providers/cipher/CipherEncryptionProvider.java [330:366]
public String get(@NonNull String key) {
if (key == null || key.isEmpty()) {
if (callback != null) {
callback.onError(GET, new SecureStorageException("Key can't be NULL or empty"));
}
return null;
}
key = generateKeyWithPrefix(key);
if (!isValueSet(I_VECTOR + key) || !isValueSet(key)) {
return null;
}
try {
String value = getPref(key);
byte[] iv = getByteArray(getPref(I_VECTOR + key));
IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
KeyStore.SecretKeyEntry secretKeyEntry = (KeyStore.SecretKeyEntry) keyStore.getEntry(KEY_ALIAS, null);
if (secretKeyEntry == null) return null;
cipher.init(Cipher.DECRYPT_MODE, secretKeyEntry.getSecretKey(), ivParameterSpec);
if (value.isEmpty()) return null;
String result = new String(cipher.doFinal(Base64.decode(value, Base64.DEFAULT)), StandardCharsets.UTF_8);
if (callback != null) {
callback.onComplete(GET);
}
return result;
} catch (InvalidKeyException | BadPaddingException | IllegalBlockSizeException | InvalidAlgorithmParameterException | NoSuchAlgorithmException | UnrecoverableEntryException | KeyStoreException e) {
e.printStackTrace();
if (callback != null) {
callback.onError(GET, e);
}
return null;
}
}