Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: BAd Padding exception

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Thanked 0 Times in 0 Posts

    Default BAd Padding exception

    well, i have problem with my program regarding AeS ecryption and decryption,,.
    I have successful encrypt a file using 128bit AES/ECB/PKCS7Padding.but i failed to decrypt the file.
    public byte[][] decrypt(byte[][] data) throws GeneralSecurityException, Exception {
            Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
            RSAPrivateKey privKey = (RSAPrivateKey) readPrivateKey(keyPath);
            Cipher cipherA = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");
            Cipher cipher = Cipher.getInstance("RSA/ECB/NOPadding", "BC");
            Cipher cipherA2 = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");
            //    RSAPublicKey pubKey = (RSAPublicKey) readKeyFromFile(keyPath);
            cipher.init(Cipher.DECRYPT_MODE, privKey);
            secretKey = cipher.doFinal(data[2]);
            System.out.println("Encrypted Key="+new String(data[2])+"\n"+"Encrypted data"+new String(data[1]));
            System.out.println("SecretKey="+new String(secretKey));
            SecretKeySpec skeySpec = new SecretKeySpec(secretKey, "AES");
            cipherA2.init(Cipher.DECRYPT_MODE, skeySpec);
           cipherData =cipherA2.doFinal(data[0]);
            cipherA.init(Cipher.DECRYPT_MODE, skeySpec);
            cipherFileName = cipherA.doFinal(data[1]);
            decryp[0]= cipherData;
            decryp[1]= secretKey;
            System.out.println("data="+new String(decryp[0])+"\n"+"Encrypted data"+new String(data[1]));
            System.out.println("Decrepted Key"+new String(decryp[1])+"\n"+"Encrypted key="+new String(data[2]));
            return decryp;
    well, i get cipherFileName..

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,701 Times in 2,651 Posts

    Default Re: BAd Padding exception

    Cross posted at BAd Padding exception - Java Forums

Similar Threads

  1. SecurityManager exception
    By phpuser123 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 20th, 2010, 05:04 AM
  2. Exception during xml validation
    By vijeta in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 6th, 2010, 02:50 AM
  3. Exception Errors
    By TIMBERings in forum Exceptions
    Replies: 1
    Last Post: December 10th, 2009, 02:13 AM
  4. Error of "ClassNotFound Exception"
    By multicoder in forum Exceptions
    Replies: 3
    Last Post: July 1st, 2009, 02:58 PM
  5. Exception handling
    By AnithaBabu1 in forum Exceptions
    Replies: 6
    Last Post: August 27th, 2008, 09:37 AM