Examples to Encrypt / decrypt Strings like passwords

171 views
Skip to first unread message

shop.servic...@gmail.com

unread,
Aug 29, 2017, 5:12:38 PM8/29/17
to CodenameOne Discussions
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans/Eclipse/IDEA NetBeans 8.2
Desktop OS Windows 10
Simulator 7.3
Device Android & IOS

Looking to encrypt/decrypt Strings in Codename1 similar to Java package org.jasypt.util.text (StandardPBEStringEncryptor)

Have installed bouncy castle cn1lib
Have installed EncryptedStorage.install(inc.KEY);

However am not understanding how to implement encryption & decryption of Strings

Looks like it is related only to File System storage.

Thoughts?

Regards

Shai Almog

unread,
Aug 29, 2017, 11:35:41 PM8/29/17
to CodenameOne Discussions, shop.servic...@gmail.com
It's related to storage in Storage. Bouncy castle has a HUGE API for encryption of various types so this is a bit vague. You need to be more specific on the encryption type.

shop.servic...@gmail.com

unread,
Aug 31, 2017, 9:52:45 AM8/31/17
to CodenameOne Discussions, shop.servic...@gmail.com
OK, I am hardly an expert on encryption, so please forgive my ignorance.

I want to encrypt/decrypt a String like password etc.
In my Swing application I use org.jasypt.encryption.pbe.StandardPBEStringEncryptor

Ideally I would like to use a compatible cypher in codename1.
  • Algorithm: PBEWithMD5AndDES.
  • Key obtention iterations: 1000.
  1. Create an instance (using new).
  2. Set a password (using setPassword(String) or setPasswordCharArray(char[])).
  3. Perform the desired encrypt(String) or decrypt(String) operations.

Can you point me in the direction of full examples of implementing this?

Regards

Shai Almog

unread,
Aug 31, 2017, 11:38:40 PM8/31/17
to CodenameOne Discussions, shop.servic...@gmail.com
This uses SHA1 for encoding: https://stackoverflow.com/questions/38673149/how-to-hash-data-with-custom-key-using-sha1digest-algorithm-in-codenameone/38680719#38680719

You can probably replace SHA1 with MD5Digest to get the same result for MD5. There are several classes with PBE too but this requires digging in deeper into the code.

shop.servic...@gmail.com

unread,
Sep 1, 2017, 10:07:56 AM9/1/17
to CodenameOne Discussions, shop.servic...@gmail.com
Sorry, This is not helpful.

I have looked at the examples @ http://www.bouncycastle.org/documentation.html
However several Classes they use are not found in the BouncyCastleCN1Lib therefore won't link

Can someone point me to complete code examples that will encrypt/decrypt MD5 that compiles with 
BouncyCastleCN1Lib ?

Regards.

Shai Almog

unread,
Sep 2, 2017, 2:02:57 AM9/2/17
to CodenameOne Discussions, shop.servic...@gmail.com
The bouncy castle libs are based on the old J2ME version of bouncy castle. You can probably google the encryption you want and J2ME to find code samples.

shop.servic...@gmail.com

unread,
Sep 2, 2017, 9:21:34 AM9/2/17
to CodenameOne Discussions, shop.servic...@gmail.com
Not much luck, example after example does no compile for one method not being supported in Cosenameone or another.

Is there not anyone in a codenameone user group that uses this library and can share some working code?

Regards.


On Saturday, September 2, 2017 at 2:02:57 AM UTC-4, Shai Almog wrote:

Shai Almog

unread,
Sep 3, 2017, 12:17:05 AM9/3/17
to CodenameOne Discussions, shop.servic...@gmail.com
Lots of people use this library but because it's so versatile everyone uses it differently. I'm unclear on what doesn't work for you?

shop.servic...@gmail.com

unread,
Sep 3, 2017, 9:54:46 AM9/3/17
to CodenameOne Discussions, shop.servic...@gmail.com
I don't see any complete examples.

If there are lots of people using it, how can I get to se people and ask for sample usages.

My challenge is the examples I have tried do not link generally use java classes not supported in codename1.

Can you please point me to complete code samples?

Regards.

Shai Almog

unread,
Sep 4, 2017, 12:18:25 AM9/4/17
to CodenameOne Discussions, shop.servic...@gmail.com
The examples are only blocks and hence complete. I'm not sure what sort of example you would expect? 

shop.servic...@gmail.com

unread,
Sep 4, 2017, 9:10:00 AM9/4/17
to CodenameOne Discussions, shop.servic...@gmail.com
An example the shows what libs to import, exactly what methods to call to encrypt a "Hello World" String, Print out the Ascii String, then decrypt the encrypted String, print it out.

Examples that demonstrate the DES encryption etc.

Unfortunately this is not intuitive for me and ask for your help in providing a complete runnable example.

Regards


On Monday, September 4, 2017 at 12:18:25 AM UTC-4, Shai Almog wrote:

Shai Almog

unread,
Sep 4, 2017, 11:42:25 PM9/4/17
to CodenameOne Discussions, shop.servic...@gmail.com
Import is pretty easy in an IDE, the community support can only go so far as I personally handle anywhere from 300 to 500 emails per day...
We do need better docs for a lot of cn1libs including this one but unfortunately we don't have them. We need the communities help in improving these docs: https://www.codenameone.com/blog/tip-edit-docs-fun-profit.html
Reply all
Reply to author
Forward
0 new messages