I have tried with simple string with out giving UTF-8 format.

byte[] bts = encrypted.getBytes();
byte[] decrypted = cipher.doFinal(bts);

Then also it will give same error.

Thanks,
Rashmi



On Apr 12, 6:06 pm, Marcin Orlowski <[email protected]> wrote:
> Blind shot -> String != byte[] for UTF-8 and I suspect this false assumption
> nukes your code.
>
> Regards,
> Marcin Orlowski
>
> *Tray Agenda <http://bit.ly/trayagenda>* - keep you daily schedule handy...
> WebnetMobile on *Facebook <http://webnetmobile.com/fb/>* and
> *Twitter<http://webnetmobile.com/twitter/>
>
> *
> On 12 April 2011 14:52, rashmi <[email protected]> wrote:
>
> > Hi,
> > I am using Asymmetric Cipher RSA algorithm for encryption and
> > decryption. I am generating private and public keys and using them for
> > encryption and decryption respectively. Following is the code snippet.
>
> >  KeyPair keypair =
> > KeyPairGenerator.getInstance("RSA").generateKeyPair();
>
> >  private  Cipher cipher = = Cipher.getInstance("RSA");
>
> > public String encrypt(String plaintext) throws Exception{
> >        this.cipher.init(Cipher.ENCRYPT_MODE,
> > this.keypair.getPrivate());
> >        byte[] bytes = plaintext.getBytes("UTF-8");
>
> >        byte[] encrypted =  cipher.doFinal(bytes);
>
> >        return new String(encrypted);
> >    }
>
> >    public String decrypt(String encrypted) throws Exception{
> >        this.cipher.init(Cipher.DECRYPT_MODE,
> > this.keypair.getPublic());
> >        byte[] bts = encrypted.getBytes("UTF-8");
>
> >        byte[] decrypted = cipher.doFinal(bts);
>
> >        return new String(decrypted,"UTF-8");
> >    }
>
> > Encryption is working fine. But while decryption it is throwing the
> > error "java.lang.ArrayIndexOutOfBoundsException: too much data for RSA
> > block". Please let me know how to resolve this problem. Please suggest
> > me if any other asymmetric algorithms to work on large data.
>
> > Thank you,
> > Rashmi
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to