• Register
0 votes
1.9k 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 26 views
26 views
Problem: Which of the following is NOT a rule that must be followed when naming identifiers? A. Identifiers for constants should use an underscore between words. B. Identifiers should use periods to separate words. C. Identifiers should list the data type at the end of the name. D. Identifiers can contain spaces.
asked Mar 9, 2020 ArifulIslam 5.6k points
1 vote
2 answers 117 views
117 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 30 views
30 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 73 views
73 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 221 views
221 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 62 views
62 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 224 views
224 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
0 votes
1 answer 369 views
369 views
Problem : I am getting bellow error while using Sockets java.net.socketexception: software caused connection abort: socket write error
asked Oct 19, 2019 peterlaw 6.9k points