· 7 years ago · Aug 21, 2018, 05:29 PM
1EncryptionException: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
2public String decrypt( String encryptedString ) throws EncryptionException
3{
4 if ( encryptedString == null || encryptedString.trim().length() <= 0 )
5 throw new IllegalArgumentException( "encrypted string was null or empty" );
6
7 try
8 {
9 SecretKey key = keyFactory.generateSecret( keySpec );
10 cipher.init( Cipher.DECRYPT_MODE, key );
11 BASE64Decoder base64decoder = new BASE64Decoder();
12 byte[] cleartext = base64decoder.decodeBuffer( encryptedString );
13 byte[] ciphertext = cipher.doFinal( cleartext );
14
15 return bytes2String( ciphertext );
16 }
17 catch (Exception e)
18 {
19 throw new EncryptionException( e );
20 }
21}