×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    5

    run j2me code on symbian belle SDK?

    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:

    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();
            }
        }
        
    }
    how can I run it on the emiolator? and can I use normal java or specialy JCE in programming a nokia s60 devices?
    I will be very appreciated if someone can help me

  2. #2
    Nokia Developer Expert
    Join Date
    Aug 2007
    Posts
    1,595

    Re: run j2me code on symbian belle SDK?

    Hello JoSmith,

    to start with JCE development including SATSA-CRYPTO, you might want to check this resource on Java Developer's Library:

    Java Developer's Library 3.11 > Developer's guides > Security > Security and trust services > Encrypted messages: SATSA-CRYPTO > Using SATSA-CRYPTO

    http://library.developer.nokia.com/i...D0DE116F8.html

    Regards,
    r2j7
    [URL="http://library.forum.nokia.com/java"][B] >>> Java Developer's Library <<<[/B][/URL]
    [URL="https://www.developer.nokia.com/Resources/Support/Technical_support.xhtml"] [B]>>> Technical Support for Java ME development <<<[/B][/URL]
    [URL="https://publish.ovi.com/info/"][B]>>> Nokia Publish: reach millions of Nokia users worldwide through Nokia Store <<<[/B][/URL]

Similar Threads

  1. Symbian Belle compilation issue
    By chintandhruva in forum Symbian Tools & SDKs
    Replies: 7
    Last Post: 2011-11-22, 17:42
  2. problem with nokia 701 symbian belle ...
    By super_rider in forum General Development Questions
    Replies: 1
    Last Post: 2011-11-04, 17:45
  3. Why called Symbian Anna, Symbian Belle?
    By patrickz in forum Symbian
    Replies: 7
    Last Post: 2011-08-25, 11:03
  4. Can I call Symbian C++ code from J2me code?
    By Rupa in forum Mobile Java General
    Replies: 6
    Last Post: 2010-11-24, 13:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×