[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bouncycastle-crypto-dev
Subject:    Re: [dev-crypto] java.lang.IllegalArgumentException: no IV set
From:       David Hook <dgh () bund ! com ! au>
Date:       2007-06-18 10:14:46
Message-ID: 1182161686.3408.89.camel () echidna
[Download RAW message or body]


CFB mode requires an initialisation vector (IV) and you'll need to make
sure it is the same for decryption as it is for encryption. In the
example below c1.getIV() will return the IV the cipher generated.

You'll probably find that the system you are dealing with uses one with
every byte set to zero, but you might not.

Regards,

David

On Mon, 2007-06-18 at 14:58 +0530, Sreelatha Kancherla wrote:
> 
> Hi , 
> 
> I have to encrypt a string in AES algorithm in CFB or OFB mode. I have
> no option to change the mode or algorithm as this needs to be
> compatible with another existing system. I have to decrypt it back at
> later point to get the original string. I am using BC provider. 
> 
> Below is my piece of code to do the same: 
> 
> Encryption logic: 
> Cipher c1 = Cipher.getInstance("AES/CFB/NOPADDING", "BC"); 
> SecretKeySpec sk = new SecretKeySpec("1234567890123456".getBytes(),
> "AES"); 
> c1.init(1, sk); 
> byte[] encrBlock =
> c1.doFinal("94579012345084623451".getBytes("UTF8")); 
> 
> Decryption logic: 
> Cipher c2 = Cipher.getInstance("AES/CFB/NOPADDING", "BC"); 
> SecretKeySpec sk = new SecretKeySpec("1234567890123456".getBytes(),
> "AES"); 
> c2.init(2, sk); 
> byte[] decrBlock = c2.doFinal(encrBlock); 
> 
> Encryption is happening properly. But while executing decryption
> logic(more precisely, at c2.init()), it is throwing the following
> exception.  
> 
> java.lang.IllegalArgumentException: no IV set when one expected 
>         at
> org.bouncycastle.jce.provider.JCEBlockCipher.engineInit(JCEBlockCipher.java:482) 
>         at javax.crypto.Cipher.init(DashoA6275) 
> 
> 
> Does anyone there know what's the problem here?? What is this IV it's
> talking about?? 
> 
> Thanks in Advance. 
> 
> =====-----=====-----=====
> Notice: The information contained in this e-mail
> message and/or attachments to it may contain 
> confidential or privileged information. If you are 
> not the intended recipient, any dissemination, use, 
> review, distribution, printing or copying of the 
> information contained in this e-mail message 
> and/or attachments to it are strictly prohibited. If 
> you have received this communication in error, 
> please notify us by reply e-mail or telephone and 
> immediately and permanently delete the message 
> and any attachments. Thank you
> 
> 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic