Results 1 to 2 of 2
  1. #1
    vineet143 is offline Member
    Join Date
    Jun 2011
    Posts
    1
    Rep Power
    0

    Post i am getting javax.crypto.illegalblocksizeexception error while sending more than 4kb

    I m building a application which encrypts and decrypts data using ECC key and uses base64 des algo.My program works for only one line of data. If it exceeds its not decrypting showing above title as ERROR . I think its cache size limit , which is hampering.


    kindly note code below and HELP ME OUT!!!!!!

    package p2;
    import javax.crypto.*;
    import javax.crypto.spec.*;
    import sun.misc.BASE64Encoder;
    import sun.misc.BASE64Decoder;
    import java.security.*;

    public class encryptdecrypt {
    public String encrypt(String msg,String key)
    {

    try
    {


    if (key.length()==8)
    {

    Cipher cipher= Cipher.getInstance("DES");
    SecretKeySpec spec= new SecretKeySpec(key.getBytes(), "DES");
    cipher.init(Cipher.ENCRYPT_MODE, spec);
    byte messageArray[]=msg.getBytes("UTF8");
    messageArray= cipher.doFinal(messageArray,0,messageArray.length) ;
    msg=new BASE64Encoder().encode(messageArray);

    }





    }
    catch(Exception e)
    {
    System.out.println(e);
    }
    return msg;
    }


    public String decrypt(String msg,String key)
    {
    boolean invalid=true;



    try
    {

    Cipher cipher= Cipher.getInstance("DES");
    SecretKeySpec spec= new SecretKeySpec(key.getBytes(), "DES");
    cipher.init(Cipher.DECRYPT_MODE, spec);
    byte messageArray[]=new BASE64Decoder().decodeBuffer(msg);
    messageArray= cipher.doFinal(messageArray);
    msg="";
    for (int i=0;i<messageArray.length;i++)
    msg+=(char) messageArray[i];
    // msg.trim();

    invalid=false;

    }
    catch(Exception e)
    {
    System.out.println(e);
    invalid=true;
    }


    return msg;
    }

    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default

    Please use code tags when posting code.
    Also, where are you getting the exception?
    Full exception text and stack trace would be helpful, as well as pointing out the line it is thrown from.

    In order to do the stack trace you'll have to change your catch blocks so they do e.printStackTrace().

Similar Threads

  1. Problem with Cipher class in javax.crypto
    By vinayak.top in forum Advanced Java
    Replies: 4
    Last Post: 02-25-2011, 09:11 AM
  2. Replies: 0
    Last Post: 05-15-2010, 09:26 AM
  3. javax.crypto.Cipher
    By Bill86 in forum Advanced Java
    Replies: 1
    Last Post: 12-18-2009, 09:17 PM
  4. Replies: 1
    Last Post: 10-11-2008, 04:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •