Results 1 to 2 of 2
  1. #1
    Bverly is offline Member
    Join Date
    Sep 2010
    Posts
    2
    Rep Power
    0

    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...is
    Java Code:
     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("\n\n"+"DecryptionClass");
            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;
            decryp[2]=cipherFileName;
            System.out.println("\n\n"+"DecryptionClass");
            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..
    Last edited by Bverly; 09-26-2010 at 08:52 PM. Reason: not yet complete

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

Similar Threads

  1. Padding Problem
    By Srikar in forum Advanced Java
    Replies: 1
    Last Post: 08-20-2010, 08:39 PM
  2. OAEP Padding Problem by encryption
    By Buhmann in forum Advanced Java
    Replies: 1
    Last Post: 09-07-2009, 01:19 PM
  3. Replies: 4
    Last Post: 04-17-2009, 09:48 PM
  4. Single Component Padding
    By subb in forum AWT / Swing
    Replies: 2
    Last Post: 03-28-2009, 07:09 PM
  5. padding informaiton for PKCS#5
    By nanaji in forum Advanced Java
    Replies: 3
    Last Post: 07-31-2008, 05:36 AM

Posting Permissions

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