hello every one
I am new in Nokia programming
and I want to make application which take a text from user and decrypt it
I have the code for decryption in j2me but I have tryed thousand of times to run on symbian belle SDK but still have errors
this is my code:
how can I run it on the emiolator? and can I use normal java or specialy JCE in programming a nokia s60 devices?Code:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; import javax.crypto.ShortBufferException; import org.bouncycastle.crypto.DataLengthException; import org.bouncycastle.crypto.InvalidCipherTextException; import org.bouncycastle.crypto.engines.AESEngine; import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher; import org.bouncycastle.crypto.params.KeyParameter; import java.io.*; /** * * @author SONY */ public class CrypterBC { //<editor-fold defaultstate="collapsed" desc="data fields"> byte[] iBuffer = new byte[16]; byte[] oBuffer = new byte[512]; byte[] key = null; PaddedBufferedBlockCipher encCipher; PaddedBufferedBlockCipher decCipher; //</editor-fold> public CrypterBC() { key = "MALTOM_1MALTOM_2MALTOM_3".getBytes(); Inicialization(); } public CrypterBC(String inKey) { key = inKey.getBytes(); Inicialization(); } public CrypterBC(byte[] keyBytes) { key = new byte[keyBytes.length]; System.arraycopy(keyBytes, 0, key, 0, keyBytes.length); Inicialization(); } private void Inicialization() { encCipher = new PaddedBufferedBlockCipher(new AESEngine()); encCipher.init(true, new KeyParameter(key)); decCipher = new PaddedBufferedBlockCipher(new AESEngine()); decCipher.init(false, new KeyParameter(key)); } public void Reset() { if (encCipher != null) { encCipher.reset(); } if (decCipher != null) { decCipher.reset(); } } private InputStream convertStringToStream(String inRetezec) { InputStream vystup; try { vystup = new ByteArrayInputStream(inRetezec.getBytes("UTF-8")); return vystup; } catch (Exception e) { return null; } } /*private String convertStreamToString(OutputStream inOs) { String vystup; try { vystup = inOs.toString(); return vystup; } catch (Exception e) { return e.getMessage(); } }*/ public ByteArrayOutputStream encryptStringWithAes(String inRetezec) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException, DataLengthException, IllegalStateException, InvalidCipherTextException { InputStream is = convertStringToStream(inRetezec); ByteArrayOutputStream os = new ByteArrayOutputStream(); String vystup; try { int noBytesRead = 0; //number of bytes read from input int noBytesProcessed = 0; //number of bytes processed while ((noBytesRead = is.read(iBuffer)) >= 0) { noBytesProcessed = encCipher.processBytes(iBuffer, 0, noBytesRead, oBuffer, 0); //System.out.println(noBytesProcessed +" bytes processed"); os.write(oBuffer, 0, noBytesProcessed); } noBytesProcessed = encCipher.doFinal(oBuffer, 0); //System.out.println(noBytesProcessed +" bytes processed"); os.write(oBuffer, 0, noBytesProcessed); os.flush(); vystup = os.toString(); //return vystup; return os;} catch (IOException e) { //return e.getMessage(); return null; } } public String decryptStringWithAes(InputStream inRetezec) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException, DataLengthException, IllegalStateException, InvalidCipherTextException { InputStream is = inRetezec; OutputStream os = new ByteArrayOutputStream(); String vystup; try { int noBytesRead = 0; //number of bytes read from input int noBytesProcessed = 0; //number of bytes processed while ((noBytesRead = is.read(iBuffer)) >= 0) { System.out.println(noBytesRead +" bytes read"); noBytesProcessed = decCipher.processBytes(iBuffer, 0, noBytesRead, oBuffer, 0); System.out.println(noBytesProcessed +" bytes processed"); os.write(oBuffer, 0, noBytesProcessed); } System.out.println(noBytesRead +" bytes read"); noBytesProcessed = decCipher.doFinal(oBuffer, 0); System.out.println(noBytesProcessed +" bytes processed"); os.write(oBuffer, 0, noBytesProcessed); os.flush(); vystup = new String(os.toString()); return vystup; } catch (java.io.IOException e) { return e.getMessage(); } } }
I will be very appreciated if someone can help me

Reply With Quote

