{"id":7183,"date":"2014-05-27T08:59:02","date_gmt":"2014-05-27T08:59:02","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/05\/27\/bad-padding-exception-collection-of-common-programming-errors\/"},"modified":"2014-05-27T08:59:02","modified_gmt":"2014-05-27T08:59:02","slug":"bad-padding-exception-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/05\/27\/bad-padding-exception-collection-of-common-programming-errors\/","title":{"rendered":"Bad Padding Exception-Collection of common programming errors"},"content":{"rendered":"<p>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<\/p>\n<pre><code>Exception in thread \"main\" javax.crypto.BadPaddingException: Given final block not properly padded\n    at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:811)\n    at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:676)\n    at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:313)\n    at javax.crypto.Cipher.doFinal(Cipher.java:2087)\n    at me.mrkirby153.test.tcp.TCP_Server_AES.decrypt(TCP_Server_AES.java:52)\n    at me.mrkirby153.test.tcp.TCP_Server_AES.main(TCP_Server_AES.java:37)\n    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\n    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n    at java.lang.reflect.Method.invoke(Method.java:606)\n    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)\n<\/code><\/pre>\n<p>Someone suggested that there was an issue between PHP and Java using a different padding method (or none at all).<\/p>\n<p>PHP<\/p>\n<pre><code>\n\n\n    \n        <br \/>\n        <\/code><\/pre>\n<h4><code>Credentials<\/code><\/h4>\n<pre>\n        \n    \n    \n        \n        \n    \n    \n        \n        \n    \n    <br \/>\n    \n        \n        \n    \n    <br \/>\n        \n    \n\n\n<\/pre>\n<p><code>TCP_encrypt<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7183","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7183"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7183\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}