aspose file tools*
The moose likes Spring and the fly likes  javax.crypto.BadPaddingException: Given final block not properly padded Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark " javax.crypto.BadPaddingException: Given final block not properly padded" Watch " javax.crypto.BadPaddingException: Given final block not properly padded" New topic
Author

javax.crypto.BadPaddingException: Given final block not properly padded

sze sze chan
Greenhorn

Joined: Jul 27, 2011
Posts: 18
Hi all !
I'm very new to spring and eclipse, and I'm currently working on a codeEnhancement project.
It's my second day to post on this Forum(the only one forum i ever entered), and I think i'm already falling in love with this place!

I'm currently trying to decrypt a password from a decrypt file and use the password to connect to oracle database.
However, I've encourntered a number of errors with this

the first Error is when i set my proxy in eclipse, The error log pops out and states that:
Keybinding conflicts occurred.They may interfere with normail accelerator operation
org.eclipse.core.runtime.AssertionFailedException:assertion failed:
Unhandled event loop exception

Any help will be much appreciated



When i run my codes, it hits the following error:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'PoolingDao' defined in class path resource [jobmgmt_beans.xml]: Invocation of init method failed; nested exception is javax.crypto.BadPaddingException: Given final block not properly padded
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at net.CodeEnhancement.JobMgmt.main(JobMgmt.java:118)
Caused by: javax.crypto.BadPaddingException: Given final block not properly padded
at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..)
at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..)
at com.sun.crypto.provider.AESCipher.engineDoFinal(DashoA13*..)
at javax.crypto.Cipher.doFinal(DashoA13*..)
at net.CodeEnhancement.Scrambler.unscramble(Scrambler.java:76)
at net.CodeEnhancement.JdbcDao.decrypt(JdbcDao.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1544)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 12 more


I've read some about BadPaddingException and there are people suggeting to store the encrypted variable in byte[].
I've tried it inside my DAO, but it still hits the same error during runtime.

Below is my JdbcDao.java:



and my jobmgmt_beans.xml which has the bean id= PoolingDao:



Any help will be much appreciated
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42601
    
  65
While we can't be sure what's going on since we don't know what the Scrambler and Encryptor classes are doing, calling "toString" on the output is a read flag - assuming that it converts a byte[] to a string, not specifying the encoding makes the code platform-dependent.

Make sure the key and the ciphertext are never stored (or used) as strings anywhere.


Ping & DNS - my free Android networking tools app
sze sze chan
Greenhorn

Joined: Jul 27, 2011
Posts: 18
Ulf Dittmer wrote:While we can't be sure what's going on since we don't know what the Scrambler and Encryptor classes are doing, calling "toString" on the output is a read flag - assuming that it converts a byte[] to a string, not specifying the encoding makes the code platform-dependent.

Make sure the key and the ciphertext are never stored (or used) as strings anywhere.


Hi, thank you for your reply, I'm still keep hitting the same BadPaddingException
I will really appreciate it if you could help, thanks

this is my Scramble.java:


and Encryptor.java
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javax.crypto.BadPaddingException: Given final block not properly padded