• Register
0 votes
2.8k views

Problem :

I am new to the socket programming. I have tried to write server and client socket program my server is trying to send a encrypted message to my client.

But I am facing below Exception at byte[] encrypt = cipher2.doFinal(result_Bytes);

javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher
    at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:750)
    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:2086)

How can I fix above error?

8 4 2
2,300 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

I also had faced a similar issue. The root cause of this issue can vary for different cases.

If you want to decrypt a value which was not encoded properly as shown below.

byte[] encryptedBytes = Base64.decodeBase64(encryptedBase64String);

If your String is misconfigured for any reason or it is encoded wrongly then you may see the error as " Input length must be multiple of 16 when decrypting with padded cipher"

Another case if you are using the encoded string in any url and trying to pass it in the base64Encoded value in url then it will fail. To fix it you should do the URLEncoding and then you can pass in the token, it will surely work.


If you are integrating it with one of the vendors then in that case I found that I had to do the encryption of Base64 using the URLEncoder but after that I need not decode it as it was done internally by a Vendor

5 2 1
4,980 points

Related questions

0 votes
1 answer 21 views
21 views
Problem: any help to deal with this situation ? thank you , Input length must be multiple of 16 when decrypting with padded cipher.
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
0 answers 2 views
2 views
Problem: packet_write_wait: connection to port 22: broken pipe, can anyone here who can answer me.
asked 1 day ago niyatiry 2.9k points
0 votes
1 answer 3 views
3 views
Problem: Please kindly tell me the solution of it, java.net.socketexception: broken pipe (write failed)
asked Apr 2 Ifra 24.4k points
1 vote
2 answers 211 views
211 views
Problem: I am able to login through webservices api to particular account on 'Oracle on demand'. When i tries to call 'accountQueryPage' method of the stub class (Stub class is generated with help Account.wsdl file), i got the following exception java.net.SocketException: Software caused connection abort: recv failed Can anyone give me some pointers.
asked Mar 27, 2020 LizzyM 6.1k points
2 votes
1 answer 38 views
38 views
Problem: I am able to login through webservices api to particular account on 'Oracle on demand'. When i tries to call 'accountQueryPage' method of the stub class (Stub class is generated with help Account.wsdl file), i got the following exception java.net.SocketException: Software caused connection abort: recv failed Can anyone give me some pointers.
asked Mar 24, 2020 LizzyM 6.1k points
0 votes
1 answer 105 views
105 views
Problem: I am seeing "{writer,send_failed,{error,closed}}" error on server side and "java.net.SocketException: Connection reset by peer: socket write error" error on java client side intermittently. What could possibly go wrong here? Both server and ... rabbitmq.client.impl.ChannelN.basicPublish(ChannelN.java:630) at com.rabbitmq.client.impl.ChannelN.basicPublish(ChannelN.java:621) Please help me.
asked Mar 23, 2020 LizzyM 6.1k points
0 votes
1 answer 278 views
278 views
Problem : I am trying to implement an HTTP Server using Sockets but getting bellow error java net socketexception connection reset by peer socket write error
asked Oct 31, 2019 peterlaw 6.9k points
0 votes
1 answer 71 views
71 views
Problem : I am struggling to find the solution for the bellow error java net socketexception software caused connection abort recv failed
asked Oct 31, 2019 peterlaw 6.9k points
0 votes
3 answers 276 views
276 views
Problem : I am trying to setup a SSL Socket connection. But i am getting below error javax.net.ssl.sslhandshakeexception received fatal alert bad_certificate
asked Oct 23, 2019 peterlaw 6.9k points