Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find verify the encryption strength of my JDK security Providers?

I have this little program that prints out all of the supported providers in my JDK installation but I am wondering if anyone knows how I can change this program to also print out the "strength" of each of the Providers?

import java.security.Provider; 
import java.security.Security; 

public class SecurityListings 
{ 
  public static void main(String[] args) 
  { 
    for (Provider provider : Security.getProviders()) 
    { 
      System.out.println("Provider: " + provider.getName()); 
      for (Provider.Service service : provider.getServices()) 
      { 
        System.out.println(" Algorithm: " + service.getAlgorithm());

      } 
    } 
  }

} 
like image 914
djangofan Avatar asked Jun 04 '12 19:06

djangofan


2 Answers

Cipher.getMaxAllowedKeyLength()

Pass in the transformation and it will return the highest allowed key.

Here is an easy check

public bool isUnlimitedKeyStrength() {
    return Cipher.getMaxAllowedKeyLength("AES") == Integer.MAX_VALUE;
}
like image 90
Andrew T Finnell Avatar answered Sep 21 '22 22:09

Andrew T Finnell


Groovy script that answers the question, thanks to help from Andrew Finnell:

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
    }
}

And a windows batch file to run it:

@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
like image 43
djangofan Avatar answered Sep 19 '22 22:09

djangofan