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.
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
You can try using DES from JSR 177, refer to http://wiki.forum.nokia.com/index.ph..._using_JSR-177
See also Bouncy Castle: http://www.bouncycastle.org/java.html
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
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
I typed "tiny encryption algorithm java" into Google... the top hit in the results was: Java/J2ME Trivial Encryption Algorithm (TEA) implementation.
Unlikely, unless you encrypt it. Nothing in the specification requires the device to encrypt RMS data for you.
Graham.
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
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).
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
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).
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.
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
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:
For base64 Class i have used this link : http://jcs.mobile-utopia.com/jcs/9049_Base64.htmlCode: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; }
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
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; }