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

[iaik-jce] Doubt in RSA encryption



when i tried to encrypt the data using RSA encryption the data size that is
above 64 bytes is not getting encrypted and decrypted properly.

this is the code i am using and the cipher is not getting decrypted. is
there any restriction on the amount of data that is used for encryption and
decryption.
thanks in advance
phani

this is the fragment of code that is giving problem:

class EncwithPubKey{
 public static void main(String[] args)throws Exception{
  Security.addProvider(new IAIK());
  KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA");
  keygen.initialize(1024);
  KeyPair keypair = keygen.generateKeyPair();
  PublicKey pk = keypair.getPublic();
  PrivateKey privkey = keypair.getPrivate();
  String data = getData("checkbook.txt");
  String enc_data = encrypt(data,pk);
  String dec_data = decrypt(enc_data,privkey);
  putDocument(dec_data,"new.txt");
 }


 public static String encrypt(String data, PublicKey pk)throws Exception
 {
  Cipher rsa_cipher = Cipher.getInstance("RSA");
  rsa_cipher.init(Cipher.ENCRYPT_MODE,pk);
  byte[] enc_data = rsa_cipher.doFinal(data.getBytes());
  return (new String(enc_data));
 }

 public static String decrypt(String encdata, PrivateKey privkey) throws
Exception
 {
  Cipher rsa_cipher = Cipher.getInstance("RSA");
  rsa_cipher.init(Cipher.DECRYPT_MODE,privkey);
  byte[] dec_data = rsa_cipher.doFinal(encdata.getBytes());
  return (new String(dec_data));
 }
}



--
Mailinglist-archive at http://jcewww.iaik.at/mailarchive/iaik-jce/jcethreads.html

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