Skip to content

Commit

Permalink
Workaround a cipher issue in Android 4.3
Browse files Browse the repository at this point in the history
[]

Issue: #2755

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=169249093
  • Loading branch information
erdemguven authored and ojw28 committed Sep 20, 2017
1 parent ca4d482 commit 8b43d89
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public CachedContentIndex(File cacheDir, byte[] secretKey, boolean encrypt) {
if (secretKey != null) {
Assertions.checkArgument(secretKey.length == 16);
try {
cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher = getCipher();
secretKeySpec = new SecretKeySpec(secretKey, "AES");
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
throw new IllegalStateException(e); // Should never happen.
Expand Down Expand Up @@ -354,6 +354,18 @@ private CachedContent addNew(String key, long length) {
return cachedContent;
}

private static Cipher getCipher() throws NoSuchPaddingException, NoSuchAlgorithmException {
// Workaround for https://issuetracker.google.com/issues/36976726
if (Util.SDK_INT == 18) {
try {
return Cipher.getInstance("AES/CBC/PKCS5PADDING", "BC");
} catch (Throwable ignored) {
// ignored
}
}
return Cipher.getInstance("AES/CBC/PKCS5PADDING");
}

/**
* Returns an id which isn't used in the given array. If the maximum id in the array is smaller
* than {@link java.lang.Integer#MAX_VALUE} it just returns the next bigger integer. Otherwise it
Expand Down

0 comments on commit 8b43d89

Please sign in to comment.