Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Exception pad block corrupted using AESLight from BouncyCastle

843811Aug 30 2006 — edited Aug 31 2006
Hi all!

I�m trying to encrypt and decrypt using AESLight from Bouncy Castle to provide cryptographi to my mobile application. I encrypt the text with no problems, and sometimes i decrypted with no problems to!
But, with some messages i got the follow exception:
org.bouncycastle.crypto.InvalidCipherTextException: pad block corrupted
	at org.bouncycastle.crypto.paddings.PKCS7Padding.padCount(Unknown Source)
	at org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher.doFinal(Unknown Source)
	at softcomex.sfw2go.server.seguranca.TranslatorAESLight.processMsg(TranslatorAESLight.java:40)
	at softcomex.sfw2go.server.Waiter.sendMessageToClient(Waiter.java:251)
	at softcomex.sfw2go.server.Waiter.run(Waiter.java:211)
My class that uses AESLight:
public TranslatorAESLight (byte[] key, boolean cripto)
	{
		this.keyAES = new byte[16];
		System.arraycopy(key, 0, this.keyAES, 0, key.length>16?16:key.length);
		
		this.cripto = cripto;
	}
And, when I have to encrypt/decrypt i call the method processMsg:
public byte[] processMsg (String msg)
	{		
		byte[] msgReturn = null;
		int length = 0;
		
		BlockCipher engine = new AESLightEngine();
		BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(engine));
		KeyParameter key = new KeyParameter(keyAES);
		cipher.init(cripto, key);
		
		msgReturn = new byte[cipher.getOutputSize(msg.getBytes().length)];
		length = cipher.processBytes(msg.getBytes(), 0, msg.getBytes().length, msgReturn, 0);
		
		try {
			cipher.doFinal(msgReturn, length);
		} catch ( Exception e) {
			e.printStackTrace();
		}
		
		return msgReturn;
	}
Please, there is something wrong with this code?

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 28 2006
Added on Aug 30 2006
2 comments
1,384 views