I have a unit test which passes in Java 8+ and fails on Java 7 because GCM mode doesn't seem to be supported in Java 7 and earlier.
I know that I can attempt to Create a cipher with the transform e.g. AES/GCM/PKCS5Padding
and catch NoSuchAlgorithmException
, but that exception might be thrown just for that particular transform and not just because GCM mode itself isn't supported (within any transform).
I can also just check for the JVM version, but that wouldn't be a valid check for an environment where a 3rd-party crypto library is in use (e.g. BouncyCastle) or a JVM with built-in support from another vendor which happens to include support for GCM.
I'd prefer to skip the test only if GCM in general is not supported, and not just if the particular (and complete) transform I choose in my code is not supported.
Is it possible to detect supported cipher block modes from Java? Or is it only possible to try a particular transform and see if it works?