diff --git a/lib/src/main/java/io/ably/lib/util/Crypto.java b/lib/src/main/java/io/ably/lib/util/Crypto.java index b45a71ac3..c44de568b 100644 --- a/lib/src/main/java/io/ably/lib/util/Crypto.java +++ b/lib/src/main/java/io/ably/lib/util/Crypto.java @@ -37,7 +37,7 @@ public class Crypto { public static final String DEFAULT_ALGORITHM = "aes"; - public static final int DEFAULT_KEYLENGTH = 256; // bits + public static final int DEFAULT_KEYLENGTH = is256BitsSupported() ? 256 : 128; // bits public static final int DEFAULT_BLOCKLENGTH = 16; // bytes /** @@ -289,6 +289,19 @@ private static final int getPaddedLength(int plaintextLength) { }; } + /** + * Determine whether or not 256-bit AES is supported. (If this determines that + * it is not supported, install the JCE unlimited strength JCE extensions). + * @return + */ + private static boolean is256BitsSupported() { + try { + return Cipher.getMaxAllowedKeyLength(DEFAULT_ALGORITHM) >= 256; + } catch (NoSuchAlgorithmException e) { + return false; + } + } + /** * The default system SecureRandom */