Skip to content

Commit

Permalink
Set default length conditionally based on locally enabled policy
Browse files Browse the repository at this point in the history
  • Loading branch information
paddybyers committed Jul 28, 2017
1 parent 63f0251 commit adf151f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/src/main/java/io/ably/lib/util/Crypto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit adf151f

Please sign in to comment.