多亏了 Andrew Finnell 的帮助,回答了这个问题的 Groovy 脚本:
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
}
}
还有一个运行它的 Windows 批处理文件:
@echo off
set JAVA_HOME1=C:\jdk1.6.0_31
set JAVA_HOME2=C:\jdk1.6.0_16
ECHO Listings from %JAVA_HOME1%
groovy.exe --javahome %JAVA_HOME1% SecurityListings.groovy > 31.result.txt
ECHO Listings from %JAVA_HOME2%
groovy.exe --javahome %JAVA_HOME2% SecurityListings.groovy > 16.result.txt
pause