سؤال

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