Skip to content

Commit b71e7b8

Browse files
author
Karthikeyan
authored
Annotate code specific to API Level 23 and above in AWSKeyValueStore (#786)
* Secure information stored in SharedPreferences * Lower aws-android-sdk-core-test compile and target sdk version to 27 * Add a symlink to android-23.jar for core * Add a gradle task that creates a symlink to android-23.jar for AWS Core * Fix the gradle task that creates symbolic link to android-23.jar * Change config.yml to setup android-23 * Enable core, cognitoidentityprovider and cognitoauth integration tests on CircleCI * Enable core, cognitoidentityprovider and cognitoauth integration tests on CircleCI * Fix pom.xml * Improve exception handling in AWSKeyValueStore * [2.12.3] Bump the patch version of 2.12.z * Update 2.12.3 CHANGELOG * Add the missing bucket prefixes to CleanupBucketIntegrationTests * Fix a bug where migrating expirationDate in CognitoCachingCredentialsProvider crashes * [2.12.4] Update changelog and bump version * Annotate code specific to API Level 23 and above in AWSKeyValueStore
1 parent 0f50b5e commit b71e7b8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

aws-android-sdk-core/src/main/java/com/amazonaws/internal/keyvaluestore/AWSKeyValueStore.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,11 @@ public synchronized String get(String key) {
196196
// Read from store -> Base64 decode -> decrypt -> convert to string
197197
final String encryptedData = sharedPreferences.getString(actualKey, null);
198198
byte[] iv = getInitializationVector(actualKey);
199-
String decryptedDataInString = decrypt(apiLevel >= ANDROID_API_LEVEL_23
200-
? new GCMParameterSpec(CIPHER_AES_GCM_NOPADDING_TAG_LENGTH_LENGTH_IN_BITS, iv)
201-
: new IvParameterSpec(iv), encryptedData);
199+
String decryptedDataInString = decrypt(
200+
//@apiLevel23Start
201+
apiLevel >= ANDROID_API_LEVEL_23 ? new GCMParameterSpec(CIPHER_AES_GCM_NOPADDING_TAG_LENGTH_LENGTH_IN_BITS, iv) :
202+
//@apiLevel23End
203+
new IvParameterSpec(iv), encryptedData);
202204
cache.put(key, decryptedDataInString);
203205
return decryptedDataInString;
204206
} catch (Exception ex) {
@@ -233,9 +235,11 @@ public void put(String key, String value) {
233235
try {
234236
// Encrypt
235237
byte[] iv = generateInitializationVector();
236-
String encryptedData = encrypt(apiLevel >= ANDROID_API_LEVEL_23
237-
? new GCMParameterSpec(CIPHER_AES_GCM_NOPADDING_TAG_LENGTH_LENGTH_IN_BITS, iv)
238-
: new IvParameterSpec(iv), value);
238+
String encryptedData = encrypt(
239+
//@apiLevel23Start
240+
apiLevel >= ANDROID_API_LEVEL_23 ? new GCMParameterSpec(CIPHER_AES_GCM_NOPADDING_TAG_LENGTH_LENGTH_IN_BITS, iv) :
241+
//@apiLevel23End
242+
new IvParameterSpec(iv), value);
239243

240244
// Persist
241245
sharedPreferences

0 commit comments

Comments
 (0)