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

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



The sample you provided should work without creating a new cipher instance
between encryption and decryption process (initializing the cipher also does
"reset" it), assuming that the parameters are actually the same.

However, in real application, decrypting will appear away from encrypting
and will be initiated by creating a new Cipher instance and initializing it
with parameters parsed from the algorithmID received.

Dieter Bratko

----- Original Message -----
From: <khorsh@sg.ibm.com>
To: <iaik-jce@iaik.tu-graz.ac.at>
Sent: Thursday, December 23, 1999 10:10 AM
Subject: [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/PbeWit
hSHAAnd3_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
>
>
>


smime.p7s