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