Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crypto default 256 bit length like all other libraries #329

Merged
merged 2 commits into from
Jul 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/src/main/java/io/ably/lib/util/Crypto.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* Utility classes and interfaces for message payload encryption.
*
* This class supports AES/CBC/PKCS5 with a default key length of 128 bits
* This class supports AES/CBC/PKCS5 with a default key length of 256 bits
* but supporting other key lengths. Other algorithms and chaining modes are
* not supported directly, but supportable by extending/implementing the base
* classes and interfaces here.
Expand All @@ -37,7 +37,7 @@
public class Crypto {

public static final String DEFAULT_ALGORITHM = "aes";
public static final int DEFAULT_KEYLENGTH = 128; // 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