6

JDK インストールでサポートされているすべてのプロバイダーを出力するこの小さなプログラムがありますが、このプログラムを変更して各プロバイダーの「強度」も出力する方法を誰かが知っているかどうか疑問に思っています。

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());

      } 
    } 
  }

} 
4

2 に答える 2

10

Cipher.getMaxAllowedKeyLength()

変換を渡すと、許可されている最高のキーが返されます。

簡単チェックはこちら

public bool isUnlimitedKeyStrength() {
    return Cipher.getMaxAllowedKeyLength("AES") == Integer.MAX_VALUE;
}
于 2012-06-04T20:24:44.423 に答える
1

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
于 2012-06-05T01:14:16.987 に答える