Blowfish decryption: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher

Problem : Blowfish decryption+  javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher

Solution: Always check your data whether it is a multiple of 8 bit or not.

             if(decodedBytes.length % 8 != 0){ //not a multiple of 8
                   System.out.println("decodedBytes is not padded properly in 8 bits");
                   //create a new array with a size which is a multiple of 8
                   byte[] padded = new byte[decodedBytes.length + 8 - (decodedBytes.length % 8)];
                   //copy the old array into it
                   System.arraycopy(decodedBytes, 0, padded, 0, decodedBytes.length);
                   decodedBytes = padded;
               }else{
                   System.out.println("decodedBytes is padded properly in 8 bits");
               }


For complete example, see here... . http://knowledge-serve.blogspot.in/2013/03/encryption-and-decryption-using.html

Popular posts from this blog

Android: where to run keytool command in android

Can not connect to git using ssh (Permissions 0644 for '/root/.ssh/id_rsa' are too open.

Upload file on Google cloud storage using Java servlet on google app engine