1

暗号Javaを使用してパスワード説明ロジックを実行しています。その中で、を使用して暗号のインスタンスを取得しながらcipher.getInstance("RSA/NONE/NoPadding"). 次の例外が発生しています: NoSuchAlgorithm.

同じコードがローカルの jboss サーバーのセットアップでは機能しますが、IBM-WAS サーバーのセットアップでは機能しません。ローカル jboss サーバーと WAS サーバーに違いはありますか?

public static String decrypt(String encrypted, KeyPair keys) {
    Cipher dec;
    try {

        dec = Cipher.getInstance("RSA/NONE/NoPadding"); //Exception raised
        dec.init(Cipher.DECRYPT_MODE, keys.getPrivate());

    } catch (GeneralSecurityException e) {
        throw new RuntimeException("RSA algorithm  not supported", e);//Catch block executed
    }
}

ログ:

R Caused by: java.security.NoSuchAlgorithmException: Cannot find any provider supporting RSA/NONE/NoPadding
    at java.lang.Throwable.<init>(Throwable.java:80)
    at javax.crypto.Cipher.getInstance(Unknown Source)
    at com.lsi.utils.JCryptionUtil.decrypt(JCryptionUtil.java:59)
    Caused by: java.security.NoSuchAlgorithmException: Mode: NONE not implemented
    at com.ibm.crypto.provider.RSA.engineSetMode(Unknown Source)
    at javax.crypto.Cipher$a_.a(Unknown Source)

**Jar**

Jce.jar - javax.crypto.Cipher;
bcprov-jdk15-140.jar (External security provider jar)
4

1 に答える 1

3

Oracle security provider supports only ECB mode instead of NONE. Algorithms are provided by security providers, registered to JVM and their names up to provider creators.

In situation, when you cannot know beforehand, which security providers installed in the execution environment, you may try different options. For example, like this:

Cipher cipher = null;
try {
    cipher = Cipher.getInstance("RSA/ECB/NoPadding");
} catch (NoSuchAlgorithmException e) {
    cipher = Cipher.getInstance("RSA/NONE/NoPadding");
}

Another possibility is to check installed providers on startup an make decision about algorithms

for (Provider provider : Security.getProviders()) {
    for (Provider.Service service : provider.getServices()) {
        System.out.println(provider.getName() + ": " + service.getType() + "." + service.getAlgorithm());
        // check these values and find a best match
    }
}
于 2014-12-04T14:32:01.490 に答える