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:
parent
ca4d482b59
commit
8b43d896f1
@ -99,7 +99,7 @@ import javax.crypto.spec.SecretKeySpec;
|
|||||||
if (secretKey != null) {
|
if (secretKey != null) {
|
||||||
Assertions.checkArgument(secretKey.length == 16);
|
Assertions.checkArgument(secretKey.length == 16);
|
||||||
try {
|
try {
|
||||||
cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
|
cipher = getCipher();
|
||||||
secretKeySpec = new SecretKeySpec(secretKey, "AES");
|
secretKeySpec = new SecretKeySpec(secretKey, "AES");
|
||||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
|
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
|
||||||
throw new IllegalStateException(e); // Should never happen.
|
throw new IllegalStateException(e); // Should never happen.
|
||||||
@ -354,6 +354,18 @@ import javax.crypto.spec.SecretKeySpec;
|
|||||||
return cachedContent;
|
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
|
* 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
|
* than {@link java.lang.Integer#MAX_VALUE} it just returns the next bigger integer. Otherwise it
|
||||||
|
Loading…
x
Reference in New Issue
Block a user