문제

I am migrating from JDK 1.5 to JDK 1.6. I've encountered difficult problem. Here is piece of code:

SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEWithMD5AndTripleDES");
SecretKey key = factory.generateSecret(keySpec);
Cipher ecipher = Cipher.getInstance(key.getAlgorithm());

The created Cither instances produce different results for JRE 1.5 and JRE 1.6 (jce is installed in both cases).

Why JDKs produce different results? What is the difference in java security implementation between versions 1.5 and 1.6?

도움이 되었습니까?

해결책 2

This works for both JDK 1.5 and JDK 1.6

        SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEWithMD5AndTripleDES");
        SecretKey key = factory.generateSecret(keySpec);

        // instead of key.getAlgorithm(). For compatibility with JDK 1.5
        String newAlgorithm = "PBEWithMD5AndDES"; // the same value as in JDK 1.5

        ecipher = Cipher.getInstance(newAlgorithm);

다른 팁

Here is a link to the differences between 1.5 & 1.6:

http://en.wikipedia.org/wiki/Java_6#Java_SE_6_.28December_11.2C_2006.29

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top