Workaround a cipher issue in Android 4.3

[]

Issue: #2755

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=169249093
This commit is contained in:
eguven 2017-09-19 09:07:04 -07:00 committed by Oliver Woodman
parent ca4d482b59
commit 8b43d896f1

View File

@ -99,7 +99,7 @@ import javax.crypto.spec.SecretKeySpec;
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.
@ -354,6 +354,18 @@ import javax.crypto.spec.SecretKeySpec;
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