Skip to content

Instantly share code, notes, and snippets.

@djangofan
Created June 5, 2012 01:20
Show Gist options
  • Save djangofan/2871851 to your computer and use it in GitHub Desktop.
Save djangofan/2871851 to your computer and use it in GitHub Desktop.
Groovy script to determine max strength of all your JDK ciphers
import javax.crypto.Cipher
import java.security.*
import javax.crypto.*
// Groovy script
class SecurityTests {
static void main(String[] args) {
for (Provider provider : Security.getProviders())
{
System.out.println("Provider: " + provider.getName())
for (Provider.Service service : provider.getServices() )
{
int maximum = 0;
String alg = service.getAlgorithm()
if ( getKeyStrength( alg ) == 2147483647 ) {
System.out.println(" Algorithm: " + alg +
", max" )
} else {
System.out.println(" Algorithm: " + alg +
", " + getKeyStrength( alg ) )
}
}
}
}
static int getKeyStrength( cipher ) {
int max
try {
max = Cipher.getMaxAllowedKeyLength( cipher)
} catch (NoSuchAlgorithmException e) {
e.getLocalizedMessage()
return 0
}
return max
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment