[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[iaik-jce] InvalidAlgorithmParamter exception when trying to change modefrom encrypt to decrypt within cipher



Hello,

I've looked thru' the bug reports and the mailing list archive but i can't
find any hits on this.

      Cipher pbeCipher =
Cipher.getInstance("PbeWithSHAAnd3_KeyTripleDES_CBC");
      // initialize for encryption
      pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);
      // encrypt data
      byte[] cipher_data = pbeCipher.doFinal(plain_data);

      // initialize for decryption
      pbeCipher.init(Cipher.DECRYPT_MODE, pbeKey, pbeParamSpec);
      // decrypt cipher data
      byte[] decrypted_data = pbeCipher.doFinal(cipher_data);

Basically this code was ripped off from
http://jcewww.iaik.tu-graz.ac.at/jce/doc/javadoc/iaik/security/cipher/PbeWithSHAAnd3_KeyTripleDES_CBC.html.
I'm using iaik-jce 251.

The first pbeCipher.init(Cipher.ENCRYPT_MODE,...) works fine but the second

pbeCipher.init(Cipher.DECRYPT_MODE,...) fails with the exception
InvalidAlgorithmParameter.

In order to get the code working, i modified the code as shown below.  I
just did 2 inserts (<== inserted) and
commented out 1 line (<== commented out) :

     Cipher pbeCipher =
Cipher.getInstance("PbeWithSHAAnd3_KeyTripleDES_CBC");
      // initialize for encryption
      pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);
      // encrypt data
      byte[] cipher_data = pbeCipher.doFinal(plain_data);

      Cipher pbeCipherDec =
Cipher.getInstance("PbeWithSHAAnd3_KeyTripleDES_CBC");  <== inserted
      pbeCipherDec.init(Cipher.DECRYPT_MODE, pbeKey, pbeParamSpec);
   <== inserted

      // initialize for decryption
//      pbeCipher.init(Cipher.DECRYPT_MODE, pbeKey, pbeParamSpec);     <==
commented out
      // decrypt cipher data
      byte[] decrypted_data = pbeCipher.doFinal(cipher_data);

Is there gonna be a patch for this?  I'm sorry if this was already
reported.  I can't find this problem anywhere.

thanks,

soon hin



--
Mailinglist-archive at http://jcewww.iaik.tu-graz.ac.at/mailarchive/iaik-jce/maillist.html

To unsubscribe send an email to listserv@iaik.tu-graz.ac.at with the folowing content: UNSUBSCRIBE iaik-jce