java - javax.crypto.IllegalBlockSizeException: last block incomplete in decryption AES -


i had server written in c# , client written in java.

for encrypt decrypt part, using method

 public byte[] encryptaes(string strtext) throws exception {     objcipher.init(cipher.encrypt_mode, objsecretkey);     log.d("datazz", string.valueof(strtext.getbytes("utf8")));     return objcipher.dofinal(strtext.getbytes("utf8")); }  public byte[] decryptaes(byte[] tdata) throws exception {     objcipher.init(cipher.decrypt_mode, objsecretkey);     return objcipher.dofinal(tdata); } 

it works without issues,but when try send data @ faster speed , start getting these few errors

javax.crypto.illegalblocksizeexception: last block incomplete in decryption java.net.socketexception: sendto failed: epipe (broken pipe) org.json.jsonexception: unterminated object @ character 257  

it's kinda hard trace issues because when try break point , works , happens when tried send data @ fast speed (eg: sending 5 request server in 1 second) , seems crashing randomly

anyone has idea causes this? appreciate , in advance

here's receiving part

public void run() {      tbuffer = null;     objsocket = new socket();     socketaddress socketaddress = new inetsocketaddress(strserverip, iserverport);     bterminate = false;     while(!bterminate){         try {             if(!objsocket.isconnected()) { // reconnect feature                 inumconnection++;                 objsocket.connect(socketaddress);                 // successful connect, reset connection has make 0                 inumconnection = 0;                 if(objsocketclientlistener != null)                     objsocketclientlistener.connected();             }             else {                 int numcount = objsocket.getinputstream().available();                 if(numcount>0) {                     byte[] receiveddata = new byte[numcount];                      //bytesreceived += objin.read(tbuffer, bytesreceived, tbuffer.length - bytesreceived);                     objsocket.getinputstream().read(receiveddata);                       //for first time initial                     if (tbuffer == null) {                         tbuffer = new byte[numcount];                         system.arraycopy(receiveddata, 0, tbuffer, 0, receiveddata.length);                     } else {                         byte[] newbytearray = new byte[bytesreceived + numcount];                         system.arraycopy(tbuffer, 0, newbytearray, 0, bytesreceived);                         system.arraycopy(receiveddata, 0, newbytearray, bytesreceived, receiveddata.length);                          tbuffer = new byte[bytesreceived + numcount];                         system.arraycopy(newbytearray, 0, tbuffer, 0, newbytearray.length);                     }                     bytesreceived += numcount;                     //bytesreceived += objin.read(tbuffer, bytesreceived, tbuffer.length - bytesreceived);                     while (bytesreceived > 0 && ((ipos = arrayhelper.indexof(tbuffer, bytesreceived, tdelimiter)) >= 0)) {                         int isize = ipos + 1;                          //byte[] tencrypted = base64.decode(arrays.copyof(tbuffer, ipos), base64.default);                         byte[] tencrypted = base64.decode(arrays.copyof(tbuffer, isize), base64.default);                          // remove tbuffer has decrypted successful.                         //system.arraycopy(tbuffer, isize, tbuffer, 0, (tbuffer.length - isize));                          system.arraycopy(tbuffer, isize, tbuffer, 0, (bytesreceived - isize));                         bytesreceived -= isize;                          if (tencrypted != null && tencrypted.length > 0) {                             byte[] tdecrypted = objcrypto.decryptaes(tencrypted);                             if (objsocketclientlistener != null) {                                 // call method messagereceived activity class                                 log.d("datazzzzzzzzzzzzzzzzzzzzzz", new string(tdecrypted, "utf8") + " ");                                 objsocketclientlistener.received(new string(tdecrypted, "utf8"));                             }                         }                     }                 }                 else                 {                     thread.sleep(500);                 }             }         } catch (ioexception e) {             crittercism.loghandledexception(e);             // todo auto-generated catch block             resetbuffer();             e.printstacktrace();             if (objsocketclientlistener != null)                 objsocketclientlistener.socketexception(e);             stop();            } catch (exception e) {             crittercism.loghandledexception(e);             // todo auto-generated catch block             resetbuffer();             e.printstacktrace();             if (objsocketclientlistener != null)                 objsocketclientlistener.generalsocketexception(e);             stop();           }     } }   


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -