Thread: [JSch-J2ME] AES in JSch for J2ME CDC
Status: Alpha
Brought to you by:
ymnk
From: Radovan S. <rad...@te...> - 2006-04-28 13:32:22
|
Hello! For a project I'm currently developing I use latest version of JSch for J2ME CDC (jsch-0.1.17-J2MECDC-20050224). In that version there is no support for AES. I tried to add it by mimicing BlowfishCBC.java and TripleDESCBC.java from com.jcraft.jsch.bc however it doesn't work. It ends up with IndexOutOfBoundsException somewhere in Session - decryption fails probably. As I am no expert in cryptography I cannot find the reason. Would anyone be able to help me with this? Thank you very much. Here's what I've put together for AES256CBC.java: /* -*-mode:java; c-basic-offset:2; -*- */ /* Copyright (c) 2004 ymnk, JCraft,Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of the authors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jcraft.jsch.bc; import com.jcraft.jsch.Cipher; import org.bouncycastle.crypto.BlockCipher; import org.bouncycastle.crypto.CipherParameters; import org.bouncycastle.crypto.modes.CBCBlockCipher; import org.bouncycastle.crypto.engines.AESEngine; import org.bouncycastle.crypto.params.KeyParameter; import org.bouncycastle.crypto.params.ParametersWithIV; public class AES256CBC implements Cipher { private static final int ivsize = 16; private static final int bsize = 32; private BlockCipher cipher; public int getIVSize() { return ivsize; } public int getBlockSize() { return bsize; } public void init(int mode, byte[] key, byte[] iv) throws Exception { byte[] tmp; if (iv.length > ivsize) { tmp = new byte[ivsize]; System.arraycopy(iv, 0, tmp, 0, tmp.length); iv = tmp; } if (key.length > bsize) { tmp = new byte[bsize]; System.arraycopy(key, 0, tmp, 0, tmp.length); key = tmp; } try { cipher = new CBCBlockCipher(new AESEngine()); CipherParameters param = new ParametersWithIV( new KeyParameter(key), iv); if (mode == ENCRYPT_MODE) { cipher.init(true, param); } else { cipher.init(false, param); } } catch (Exception e) { System.out.println(e); } } public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception { while (len >= 8) { cipher.processBlock(foo, s1, bar, s2); len -= 8; s1 += 8; s2 += 8; } } } Best regards Radovan Skolnik ------------------------------------------------------------------ Ing. Radovan Skolnik TEMPEST s.r.o. Department of Enterprise Management Plynarenska 7/B 821 09 Bratislava Slovak Republic E-mail: rad...@te... www: http://www.tempest.sk Tel: +421 (2) 502 67 174 Fax: +421 (2) 502 67 100 ITIL, eTOM, SLM, Networking, Telco, Management, Java and XML ------------------------------------------------------------------ |
From: <ym...@jc...> - 2006-05-01 06:47:51
|
Hi, +-From: "Radovan Skolnik" <rad...@te...> -- |_Date: Fri, 28 Apr 2006 15:30:57 +0200 _________________ | |For a project I'm currently developing I use latest version of JSch for J2ME |CDC (jsch-0.1.17-J2MECDC-20050224). In that version there is no support for |AES. I tried to add it by mimicing BlowfishCBC.java and TripleDESCBC.java |from com.jcraft.jsch.bc however it doesn't work. It ends up with |IndexOutOfBoundsException somewhere in Session - decryption fails probably. |As I am no expert in cryptography I cannot find the reason. Would anyone be |able to help me with this? Thank you very much. The current implementation has expected that the size of cipher's IV(Initial Vector) is in 8 bytes, but AES will use 16 bytes for IV. I guess that is the reason. I'll modify the code and post it to this list for your testing. Please wait for a while. Sincerely, -- Atsuhiko Yamanaka JCraft,Inc. 1-14-20 HONCHO AOBA-KU, SENDAI, MIYAGI 980-0014 Japan. Tel +81-22-723-2150 +1-415-578-3454 Fax +81-22-224-8773 Skype callto://jcraft/ |
From: <ym...@jc...> - 2006-06-06 16:53:36
|
Hi, +-From: "Radovan Skolnik" <rad...@te...> -- |_Date: Fri, 28 Apr 2006 15:30:57 +0200 _________________ | |For a project I'm currently developing I use latest version of JSch for J2ME |CDC (jsch-0.1.17-J2MECDC-20050224). In that version there is no support for |AES. I tried to add it by mimicing BlowfishCBC.java and TripleDESCBC.java |from com.jcraft.jsch.bc however it doesn't work. It ends up with |IndexOutOfBoundsException somewhere in Session - decryption fails probably. |As I am no expert in cryptography I cannot find the reason. Would anyone be |able to help me with this? Thank you very much. I have improved the code to add the support for AES ciphers, 'aes256-cbc', 'aes192-cbc' and 'aes128-cbc'. If you are interested in it, try the following version, http://j2me.jsch.org/jsch-0.1.17-J2MECDC-20060606.zip Sincerely, -- Atsuhiko Yamanaka JCraft,Inc. 1-14-20 HONCHO AOBA-KU, SENDAI, MIYAGI 980-0014 Japan. Tel +81-22-723-2150 +1-415-578-3454 Fax +81-22-224-8773 Skype callto://jcraft/ |
From: Radovan S. <rad...@te...> - 2006-06-07 07:15:04
|
Hello, Thank you very much. I will test it and in case of any problems I will let you know. Thank you once again. Best regards Radovan Skolnik -----Original Message----- From: jsc...@li... [mailto:jsc...@li...] On Behalf Of Atsuhiko Yamanaka Sent: Tuesday, June 06, 2006 6:53 PM To: rad...@te... Cc: jsc...@li... Subject: Re: [JSch-J2ME] AES in JSch for J2ME CDC Hi, +-From: "Radovan Skolnik" <rad...@te...> -- |_Date: Fri, 28 Apr 2006 15:30:57 +0200 _________________ | |For a project I'm currently developing I use latest version of JSch for J2ME |CDC (jsch-0.1.17-J2MECDC-20050224). In that version there is no support for |AES. I tried to add it by mimicing BlowfishCBC.java and TripleDESCBC.java |from com.jcraft.jsch.bc however it doesn't work. It ends up with |IndexOutOfBoundsException somewhere in Session - decryption fails probably. |As I am no expert in cryptography I cannot find the reason. Would anyone be |able to help me with this? Thank you very much. I have improved the code to add the support for AES ciphers, 'aes256-cbc', 'aes192-cbc' and 'aes128-cbc'. If you are interested in it, try the following version, http://j2me.jsch.org/jsch-0.1.17-J2MECDC-20060606.zip Sincerely, -- Atsuhiko Yamanaka JCraft,Inc. 1-14-20 HONCHO AOBA-KU, SENDAI, MIYAGI 980-0014 Japan. Tel +81-22-723-2150 +1-415-578-3454 Fax +81-22-224-8773 Skype callto://jcraft/ _______________________________________________ JSch-J2ME mailing list JSc...@li... https://lists.sourceforge.net/lists/listinfo/jsch-j2me |
From: Radovan S. <rad...@te...> - 2006-06-08 11:00:25
|
Thanx a lot - it works nicely. Thank you once again. Radovan Skolnik -----Original Message----- From: Atsuhiko Yamanaka [mailto:ym...@jc...] Sent: Tuesday, June 06, 2006 6:53 PM To: rad...@te... Cc: jsc...@li... Subject: Re: [JSch-J2ME] AES in JSch for J2ME CDC Hi, +-From: "Radovan Skolnik" <rad...@te...> -- |_Date: Fri, 28 Apr 2006 15:30:57 +0200 _________________ | |For a project I'm currently developing I use latest version of JSch for J2ME |CDC (jsch-0.1.17-J2MECDC-20050224). In that version there is no support for |AES. I tried to add it by mimicing BlowfishCBC.java and TripleDESCBC.java |from com.jcraft.jsch.bc however it doesn't work. It ends up with |IndexOutOfBoundsException somewhere in Session - decryption fails probably. |As I am no expert in cryptography I cannot find the reason. Would anyone be |able to help me with this? Thank you very much. I have improved the code to add the support for AES ciphers, 'aes256-cbc', 'aes192-cbc' and 'aes128-cbc'. If you are interested in it, try the following version, http://j2me.jsch.org/jsch-0.1.17-J2MECDC-20060606.zip Sincerely, -- Atsuhiko Yamanaka JCraft,Inc. 1-14-20 HONCHO AOBA-KU, SENDAI, MIYAGI 980-0014 Japan. Tel +81-22-723-2150 +1-415-578-3454 Fax +81-22-224-8773 Skype callto://jcraft/ |