How to check if Cipher supports certain key size?
问题 How can I check if a chosen cipher algorithm transformation supports certain key length? boolean checkAlgorithm( String encryptMethod, int keyLength ) { Cipher cipher = Cipher.getInstance(encryptMethod); int maxLength = cipher.getMaxAllowedKeyLength(encryptMethod); if ( keyLength <= maxLength && SOMETHING_ELSE ) { return true; } else { return false; } } Is there a way without doing it one by one for each transformation like: switch( encryptMethod ) { case "Blowfish": if ( keyLength <=