Bad Padding Exception-Collection of common programming errors
Recently I was experimenting with communication between a webserver and java and ended up experimenting with sockets. Putting this into production, it is a must to encrypt the data being sent to and from the java socket server and to the php webserver. As an encryption method, I am using AES. I can get the PHP web server to successfully encrypt the data and send it via a socket but I cannot get the java application to successfully decrypt the message. I keep getting
Exception in thread "main" javax.crypto.BadPaddingException: Given final block not properly padded
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:811)
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:676)
at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:313)
at javax.crypto.Cipher.doFinal(Cipher.java:2087)
at me.mrkirby153.test.tcp.TCP_Server_AES.decrypt(TCP_Server_AES.java:52)
at me.mrkirby153.test.tcp.TCP_Server_AES.main(TCP_Server_AES.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Someone suggested that there was an issue between PHP and Java using a different padding method (or none at all).
PHP
Credentials
TCP_encrypt