I am learning encryption in java, So I started making a client server program with symmetric key(AES and 3DES) encryption. I store the secret keys and initialization vectors as BLOB in my data base. I use encryption for 2 different strings. I can successfully store the keys and iv's as BLOB but when I retrieve them I am having a problem with the second string AES key and rest of the stuff is fine.
String 1:
AES 256 Key - can be stored and retrieved. AES 256 IV - can be stored and retrieved.
3DES Key - can be stored and retrieved. 3DES IV - can be stored and retrieved.
String 2:
AES 256 Key - can be stored but can be retrieved but I am not able to use the key for decryption. AES 256 IV - can be stored and retrieved.
3DES Key - can be stored and retrieved. 3DES IV - can be stored and retrieved.
The stack trace is as below:
java.security.InvalidKeyException: Illegal key size
at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1024)
at javax.crypto.Cipher.implInit(Cipher.java:790)
at javax.crypto.Cipher.chooseProvider(Cipher.java:849)
at javax.crypto.Cipher.init(Cipher.java:1348)
at javax.crypto.Cipher.init(Cipher.java:1282)
at a.AESEncrypt.decrypt(AESEncrypt.java:71)
at a.Retr1.passwordCheck(Retr1.java:279)
at a.Msgret1.csecPwdChk(Msgret1.java:244)
at a.Msgret1.doPost(Msgret1.java:95)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
I use 32 byte key to encrypt but when I decrypt I get this issue.
I installed the JCE files Unlimited Strength Policy files to C:\Program Files\Java\jre7\lib\security
It seems I added JCE Unlimited Strength Policy files of jdk1.6 to my jdk 1.7.
Now I downloaded the JCE files for jdk7 its working fine.
Thanks @ntoskrnl for your help