not necessary , is that got any way for these ?
Main Topics
Browse All TopicsHi is urgent here , i m facing some encryption and decryption problem between midlet and tomcat server , i encypted in midlet then send the tomcat server for decryption
But whenever decrypt in tomcat server, it showing IllegalBlockSizeException as below : -
Exp :Input length must be multiple of 8 when decrypting with padded cipher
Exp :javax.crypto.IllegalBlock
(StandardEngineValve.java:
at org.apache.catalina.connec
at org.apache.coyote.http11.H
at org.apache.coyote.http11.H
at org.apache.tomcat.util.net
Midlet side encryption code : -
cipher = Cipher.getInstance("DES/CB
key = new SecretKeySpec(kDESKey, 0, kDESKey.length, "DES");
iv = new IvParameterSpec(kDESiv, 0, kDESiv.length);
// Calculate ciphertext size.
int blocksize = 16;
int ciphertextLength = 0;
int remainder = nonBlockPlaintext.length % blocksize;
if (remainder == 0) {
ciphertextLength = nonBlockPlaintext.length;
}else{
ciphertextLength = nonBlockPlaintext.length - remainder + blocksize;
}
cipher.init(Cipher.ENCRYPT
ciphertext = new byte[ciphertextLength];
cipher.doFinal(nonBlockPla
// base64 encrypted ciphertext then send to tomcat server
Tomcat server side decryption : -
cipher = Cipher.getInstance("DES/CB
iv = new IvParameterSpec(kDESiv, 0, kDESiv.length);
key = new SecretKeySpec(kDESKey, 0, kDESKey.length, "DES");
cipher.init(Cipher.DECRYPT
int blocksize = 16;
int ciphertextLength = 0;
int remainder = ciphertext.length % blocksize;
if (remainder == 0) {
ciphertextLength = ciphertext.length;
}else{
ciphertextLength = ciphertext.length - remainder + blocksize;
}
decrypted = new byte[ciphertextLength];
cipher.doFinal(ciphertext,
//throw exception Input length must be multiple of 8 when decrypting with padded cipher
Its related with PKCS5Padding , i just wonder is that the midlet side or server side padding calculation is wrongly ?
Is urgent , thanks for advice
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
at the midlet side there
cipher can only call this function with these parameter
cipher.doFinal(nonBlockPla
without
- cipher.doFinal()
- cipher.doFinal( byte[] ) and etc
if i put the cipher instance as "DES/CBC/NoPadding" , using
cipher.doFinal(nonBlockPla
it will throw null exception
Can refer these website : -
http://www.herongyang.com/
http://www.obviex.com/Arti
http://www.di-mgt.com.au/c
http://www.forum.nokia.com
i had tried for ur way , but seems doesnet work .
do u know wat should i do when decrypting using this calculation ?
i follow the website references for ciphertext calculation , i think mayb my calculation in decryption should use other calculation
int blocksize = 16;
int ciphertextLength = 0;
int remainder = ciphertext.length % blocksize;
if (remainder == 0) {
ciphertextLength = ciphertext.length;
}else{
ciphertextLength = ciphertext.length - remainder + blocksize;
}
can u explain more for that ?
and then .. as u can u at the server side code there...
cipher.init(Cipher.DECRYPT
/**** Remove cipher text length
int blocksize = 16;
int ciphertextLength = 0;
int remainder = ciphertext.length % blocksize;
if (remainder == 0) {
ciphertextLength = ciphertext.length;
}else{
ciphertextLength = ciphertext.length - remainder + blocksize;
}
****/
// how should i know the exact byte size require ?
decrypted = new byte[ciphertextLength];
/** doFinal api
public final int doFinal(byte[] input,
int inputOffset,
int inputLen,
byte[] output,
int outputOffset)
throws ShortBufferException,
IllegalBlockSizeException,
BadPaddingException
**/
/**
Parameters:
input - the input buffer
inputOffset - the offset in input where the input starts
inputLen - the input length
output - the buffer for the result
outputOffset - the offset in output where the result is stored
**/
cipher.doFinal(ciphertext,
and then the code above i tested in localhost is running successfully for encryption & decryption , from midlet to tomcat localhost , but whenever i upload to server
start sending from midlet to live tomcat server , is getting error , and i checked the server log , is giving
exception :
Input length must be multiple of 8 when decrypting with padded cipher
Business Accounts
Answer for Membership
by: CEHJPosted on 2009-06-09 at 06:36:16ID: 24580936
I don't know J2ME but is it really necessary to do your own padding?