Re: ArrayIndexOutOfBoundsException

T H Panton <[email protected]> Tue, 20 Nov 2018 11:55:02 +0000
Newsgroups gmane.comp.encryption.bouncy-castle.devel
Message-ID <[email protected]>
I saw the same problem and solved it by allocating extra space in the output buffer;

Here is a useful code example I found:

byte[] output = new byte[aes.getOutputSize(plaintext.length)];

Tim.

> On 20 Nov 2018, at 07:01, lokesh kalal <[email protected]> wrote:
> 
> Hey guys ,
> Can anybody help me on this?
> 
> On Fri, Nov 16, 2018 at 10:41 AM lokesh kalal <[email protected]> wrote:
> Hi 
> I am using folllwing class to decrypt the various data packet in a loop.
> 
> public class Decryptor {
> 
> private Cipher aesDecryptCipher = null;
> 
> public byte[] Decrypt(byte[] data) {
> 		byte[] decryptedData = null;
> 		
> 		try {
> 			if (aesKeySpec == null)
> 				aesKeySpec = new SecretKeySpec(sessionKey, "AES");
> 			if (aesDecryptCipher == null) {
> 				aesDecryptCipher = Cipher.getInstance("AES", "BC");
> 				aesDecryptCipher.init(Cipher.DECRYPT_MODE, aesKeySpec);
> 			}
> 			decryptedData = aesDecryptCipher.doFinal(data);
> 			
> 		} catch (NoSuchAlgorithmException e) {
> 			Logger.d(tag, "NoSuchAlgorithmException: " + e.toString());
> 		} catch (NoSuchPaddingException e) {
> 			Logger.d(tag, "NoSuchPaddingException: " + e.toString());
> 		} catch (InvalidKeyException e) {
> 			Logger.d(tag, "InvalidKeyException: " + e.toString());
> 		} catch (IllegalBlockSizeException e) {
> 			Logger.d(tag, "IllegalBlockSizeException: " + e.toString());
> 		} catch (BadPaddingException e) {
> 			Logger.d(tag, "BadPaddingException: " + e.toString());
> 		} catch (NoSuchProviderException e) {
> 			Logger.d(tag, "aesDecrypt NoSuchProviderException: " + e.toString());
> 		} catch (IllegalStateException e) {
> 			Logger.e(tag, "aesDecrypt IllegalStateException: " + e.toString());
> 		}
> 		
> 		return decryptedData;
> 	}
> 
> }
> 
> On Thu, Nov 15, 2018 at 3:21 PM Eckenfels. Bernd <[email protected]> wrote:
> You need to provide us with a minimal code example on how you use the Cipher so we can help you. What methods do you call with which buffer length, what version is it, which cipher do you use, what do you want to achieve. It looks like you use doFinal(byte[], int) with a too short output buffer. Did you account for IV block, padding and AE Tag?
> 
> Gruss
> Bernd
> --
> http://www.seeburger.com
> ________________________________________
> From: lokesh kalal [[email protected]]
> Sent: Thursday, November 15, 2018 09:24
> To: [email protected]
> Subject: [dev-crypto] ArrayIndexOutOfBoundsException
> 
> Hi Guys ,
> Facing multiple crashes in my application.
> Is there somthing we can do to fix this?
> 
> Fatal Exception: java.lang.
> : src.length=208 srcPos=192 dst.length=16 dstPos=16 length=16
>        at java.lang.System.arraycopy(System.java:252)
>        at com.android.org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher.processBytes(PaddedBufferedBlockCipher.java:221)
>        at com.android.org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher$BufferedGenericBlockCipher.processBytes(BaseBlockCipher.java:1004)
>        at com.android.org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher.engineDoFinal(BaseBlockCipher.java:841)
>        at javax.crypto.Cipher.doFinal(Cipher.java:1340)
> 
> --
> Thanks & Regards,
> Lokesh Kalal
> 
> 
> 
> 
> 
> 
> 
> 
> 
> SEEBURGER AG            Vorstand/SEEBURGER Executive Board:
> Sitz der Gesellschaft/Registered Office:                Axel Haas, Michael Kleeberg, Axel Otto, Dr. Martin Kuntz, Matthias Feßenbecker
> Edisonstr. 1
> D-75015 Bretten         Vorsitzende des Aufsichtsrats/Chairperson of the SEEBURGER Supervisory Board:
> Tel.: 07252 / 96 - 0            Prof. Dr. Simone Zeuchner
> Fax: 07252 / 96 - 2222
> Internet: http://www.seeburger.de               Registergericht/Commercial Register:
> e-mail: [email protected]               HRB 240708 Mannheim
> 
> 
> Dieses E-Mail ist nur für den Empfänger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungsäußerung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung der SEEBURGER AG dar. Sind Sie nicht der Empfänger, so haben Sie diese E-Mail irrtümlich erhalten und jegliche Verwendung, Veröffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail ist strengstens untersagt. Weder die SEEBURGER AG noch der Absender (Eckenfels. Bernd) übernehmen die Haftung für Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anhänge auf Viren zu prüfen.
> 
> 
> This email is intended only for the recipient(s) to whom it is addressed. This email may contain confidential material that may be protected by professional secrecy. Any fact or opinion contained, or expression of the material herein, does not necessarily reflect that of SEEBURGER AG. If you are not the addressee or if you have received this email in error, any use, publication or distribution including forwarding, copying or printing is strictly prohibited. Neither SEEBURGER AG, nor the sender (Eckenfels. Bernd) accept liability for viruses; it is your responsibility to check this email and its attachments for viruses.
> 
> 
> 
> -- 
> Thanks & Regards,
> Lokesh Kalal
> 
> 
> 
> -- 
> Thanks & Regards,
> Lokesh Kalal
>