×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Regular Contributor
    Join Date
    Dec 2009
    Location
    Ghaziabad
    Posts
    244

    Question Encryption in J2ME

    Hi Experts,

    How do i start with Encryption in J2ME. Do we have TEA(Tiny Encryption Algorithm) in J2ME. Where could i found the library to use in my J2ME Application.

    Please do reply. Just waiting for the respone.
    Regards
    Rajan Verma

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: Encryption in J2ME

    You can try using DES from JSR 177, refer to http://wiki.forum.nokia.com/index.ph..._using_JSR-177
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  3. #3
    Super Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,569

    Re: Encryption in J2ME

    See also Bouncy Castle: http://www.bouncycastle.org/java.html

  4. #4
    Regular Contributor
    Join Date
    Dec 2009
    Location
    Ghaziabad
    Posts
    244

    Re: Encryption in J2ME

    thanks for replying, I have to send the data to the mysql database at server end. Before sending the data i have to encrypt it. and before saving to the database i have to decrypt the data. And vice versa for recieving the data to the mobile.

    I want to know which one is better option DES or BouncyCastle Algorithm. Need an urgent reply.

    Thanks in advance.
    Regards
    Rajan Verma

  5. #5
    Regular Contributor
    Join Date
    Dec 2009
    Location
    Ghaziabad
    Posts
    244

    Re: Encryption in J2ME

    One more question I have also used RMS in my application . The data stored in RMS is in encrypted form, is this true....or should i save the data to the local database in encrypted form.

    Please Reply.
    Regards
    Rajan Verma

  6. #6
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Encryption in J2ME

    Quote Originally Posted by rajan701v View Post
    Do we have TEA(Tiny Encryption Algorithm) in J2ME. Where could i found the library to use in my J2ME Application.
    I typed "tiny encryption algorithm java" into Google... the top hit in the results was: Java/J2ME Trivial Encryption Algorithm (TEA) implementation.

    Quote Originally Posted by rajan701v View Post
    The data stored in RMS is in encrypted form, is this true
    Unlikely, unless you encrypt it. Nothing in the specification requires the device to encrypt RMS data for you.

    Graham.

  7. #7
    Regular Contributor
    Join Date
    Dec 2009
    Location
    Ghaziabad
    Posts
    244

    Re: Encryption in J2ME

    I want to send data to the mysql server at server end using web service. Which algorithm should i use : DES or BouncyCastle

    Please Reply.
    Regards
    Rajan Verma

  8. #8
    Super Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,569

    Re: Encryption in J2ME

    Quote Originally Posted by rajan701v View Post
    I want to send data to the mysql server at server end using web service. Which algorithm should i use : DES or BouncyCastle
    You can use either one of the algorithms. Both will work, as long as both the client and server are using them correctly.

    Depending on the case, using HTTPS will also encrypt the data without any programming needed from your side (if your server has the correct certificate for HTTPS/SSL).

  9. #9
    Regular Contributor
    Join Date
    Dec 2009
    Location
    Ghaziabad
    Posts
    244

    Re: Encryption in J2ME

    Thanks petrib.
    According to the above discussion. I have used DES Encryption algo and send the data to the server in encrypted form and also sent the number of bytes recieved from doFinal() method to the web service. But i'm not able to recieve any response from the other end.

    Please reply.
    Regards
    Rajan Verma

  10. #10
    Super Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,569

    Re: Encryption in J2ME

    Is the "other end" also under your control? If so, check the "other end" that it is actually receiving the data, and then really sending something back to the client (if the server is not responding with anything, then there's of course nothing that the client can/will see/receive).

  11. #11
    Regular Contributor
    Join Date
    Dec 2009
    Location
    Ghaziabad
    Posts
    244

    Re: Encryption in J2ME

    Quote Originally Posted by petrib View Post
    Is the "other end" also under your control?
    Yes it is under my control. And i am decrypting the data and then saving to the mysql database at the server end. But still not getting any response.

    Please Reply
    Regards
    Rajan Verma

  12. #12
    Super Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,569

    Re: Encryption in J2ME

    So, are you on the server side sending the response? How? As a response to a HTTP request? Or through some other means? If so, what/how? Any errors in the code? Can you post the relevant pieces of code in case someone spots mistakes there? If you do, use the CODE tags so that the formatting remains readable.

  13. #13
    Regular Contributor
    Join Date
    Dec 2009
    Location
    Ghaziabad
    Posts
    244

    Re: Encryption in J2ME

    I am using JSR -172 Web service api and sending the data to the webservice in encrypted form. But from the server end i am not getting any response.
    One more thing, When i am sending the encrypted bytes to the webservice the application returns nothing or even closes sometimes. But when i am sending the encrypted string (converted encrypted bytes to string using new String(bytes,0,bytes.length) i am getting the null.

    At the server side i am also decrypting the data .
    Regards
    Rajan Verma

  14. #14
    Regular Contributor
    Join Date
    Dec 2009
    Location
    Ghaziabad
    Posts
    244

    Question Re: Encryption in J2ME

    How would i send the encrypted data to the server: In the form of byte array or as a String.
    Should i use Base64(to encode it to string or decode to byte array) Class before sending the data to the server.
    I need some info about Base64 Class. When sending the data to the webservice in String format. At the server the code does not decode the encoded String what should i do. ???

    Sending encoded data to the server :
    Code:
    //Variables used 
    byte[] b = "SECRET!!".getBytes();
        byte[] enMSG = new byte[10000];
        byte[] deMSG = new byte[10000];
        private int numBytes;
        FOS_SERVICEService_Stub stub;
    // End of variables used
    
    private Cipher getCipher() {
            Cipher c = null;
            try {
                c = Cipher.getInstance("DES");
            } catch (NoSuchAlgorithmException ex) {
                ex.printStackTrace();
            } catch (NoSuchPaddingException ex) {
                ex.printStackTrace();
            }
            return c;
        }
    
        public String encrypt() {
            String result = null;
            byte[] msg = "This is a text".getBytes();
            Cipher c1 = getCipher();
            try {
                c1.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(b, 0, b.length, "DES"));
                try {
                    numBytes = c1.doFinal(msg, 0, msg.length, enMSG, 0);
                    stub = new FOS_SERVICEService_Stub();
                    MyDialog.showCustomDLG("Message", "Here", Dialog.TYPE_INFO);
                    try {
                        String encode = Base64.encode(enMSG, 0, numBytes);
                        //String st_e = new String(enMSG, 0, enMSG.length);
                        MyDialog.showCustomDLG("Message", "Here"+encode, Dialog.TYPE_INFO);
                        result = stub.encryptData(encode, numBytes);
                        MyDialog.showCustomDLG("Message", "Here"+result, Dialog.TYPE_INFO);
                    } catch (RemoteException ex) {
                        ex.printStackTrace();
                    }
                } catch (IllegalStateException ex) {
                } catch (ShortBufferException ex) {
                } catch (IllegalBlockSizeException ex) {
                } catch (BadPaddingException ex) {
                }
            } catch (InvalidKeyException ex) {
            }
            return result;
        }
    Code:
    Used base64 class to decode the content to byte array and  then sent to the below method decrypt(byte[] encrypted_data,int num_of_Bytes);
    byte[] base64_decoded = Base64.decode(bt, 0, j);
                    st = Services_Sec.decryptData(base64_decoded, j);

    Code for Decoding the data at the server end:
    Code:
    private static String decrypt(byte[] encrypted_data,int num_of_Bytes) {
            String original = null;
            Cipher c1 = getCipher();
            try {
                c1.init(Cipher.DECRYPT_MODE, new SecretKeySpec(b, 0, b.length, "DES"));
                try {
                    //byte[] bte = encrypted_data.getBytes();
                    int final_text = c1.doFinal(encrypted_data, 0, num_of_Bytes, deMSG, 0);
                    original = new String(deMSG, 0, final_text);
                    //System.out.println("Decrypted : " + original);
                } catch (IllegalStateException ex) {
                    ex.printStackTrace();
                } catch (ShortBufferException ex) {
                    ex.printStackTrace();
                } catch (IllegalBlockSizeException ex) {
                    ex.printStackTrace();
                } catch (BadPaddingException ex) {
                    ex.printStackTrace();
                }
            } catch (InvalidKeyException ex) {
                ex.printStackTrace();
            }
            return original;
        }
    For base64 Class i have used this link : http://jcs.mobile-utopia.com/jcs/9049_Base64.html

    Please help. waiting for the response from your end.
    Last edited by wizard_hu_; 2012-10-02 at 10:03. Reason: [PHP] tags with Java appear providing unreadable result, at least for IE and Chrome
    Regards
    Rajan Verma

  15. #15
    Registered User
    Join Date
    Dec 2010
    Posts
    19

    Re: Encryption in J2ME

    Quote Originally Posted by rajan701v View Post
    Hi Experts,

    How do i start with Encryption in J2ME. Do we have TEA(Tiny Encryption Algorithm) in J2ME. Where could i found the library to use in my J2ME Application.

    Please do reply. Just waiting for the respone.
    try this encryption n decp--->
    where mlet.keys =
    public String keys = "XYZ9abcd5efghij2klmn7opqrst4uvwABCx6yzDE8FGHI0JKL1MNO3PQRSTUVW~!@#$%^&*()_+|-=`{}[]':?/.><;,";

    Code:
    
    public String Dcrypt(String s, int ky) {//function to decrypt data
    
            String en = "";
            String dc = s;
            String cpos;
            String a;
    
            do {
                cpos = dc.charAt(0) + "";
                String ch = dc.charAt(1) + "";
                int fc = mlet.keys.indexOf(ch.trim());
                int gop = mlet.keys.indexOf(ch.trim());
                if (cpos.equals("1")) {
                    fc = ky - fc;
                } else {
                    if (cpos.equals("2")) {
                        fc = ky + fc;
                    } else {
                        fc = fc + 40;
                    }
                }
                if (gop < 0) {
                    a = " ";
                } else {
                    a = mlet.keys.charAt(Math.abs(fc)) + "";
                }
                en = en + a;
                dc = dc.substring(2, dc.length());
            } while (dc.length() > 0);
    
            dc = null;
            cpos = null;
            a = null;
            return en;
    
    
        }
    
        public String Encrypt(String str, int ky) {//function to encrypt data
            String en = "";
            int j = 0;
            String a = null;
            int k = 0;
            for (int i = 0; i < str.length(); ++i) {
                String c = str.charAt(i) + "";
                j = mlet.keys.indexOf(c.trim());
                if (j < ky) {
                    k = ky - j;
                    a = "1";
                } else {
                    k = j - ky;
                    a = "2";
                }
                if (j > 61) {
                    k = j - (40);
                    a = "3";
                }
    
                if (j >= 0) {
                    en = en + a + mlet.keys.charAt(k);
                } else {
                    en = en + a + " ";
                }
    
            }
            a = null;
            return en;
    
        }
    /// imp enp n dep  .. *****
    
        public void rnd() {
    
            Random random = new Random();
            int ran = random.nextInt() % 62;
            ran = Math.abs(ran);
            String cky = mlet.keys.charAt(ran) + "";
            sckey = cky;
            cky = cky.trim();
            ckey = mlet.keys.indexOf(cky);
            cky = null;
            random = null;
    
        }

Similar Threads

  1. how to test j2me encryption code in speech call
    By elkourd in forum Mobile Java General
    Replies: 5
    Last Post: 2010-02-11, 19:21
  2. Drive Encryption in j2me
    By sign8th in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2010-02-02, 14:34
  3. Encryption of folder object in J2ME
    By thechameleon in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2009-07-31, 07:15
  4. Encryption in J2me and decryption in C# ??
    By iworktech_kiran in forum Mobile Java Networking & Messaging & Security
    Replies: 4
    Last Post: 2008-09-17, 15:09
  5. Data encryption/decryption in J2ME
    By divyas in forum Mobile Java General
    Replies: 1
    Last Post: 2006-05-18, 05:49

Posting Permissions

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