codenameone / CodenameOne

Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.
https://www.codenameone.com/
Other
1.7k stars 404 forks source link

RFE: SHA hashing algorithm in Codename One #2660

Open jsfan3 opened 5 years ago

jsfan3 commented 5 years ago

Today I've noted that the Codename One API is missing any "secure" hashing algorithm. I also noted that on StackOverflow everyone suggests to use the MessageDigest class that is absent in the Codename One API. That's why I've just created a self-contained class, without any import, with only a public static method the implements the SHA-256 hashing of a String (all other methods are private).

I tested it on Simulator, Android native, iOS native and Javascript, comparing the results with http://www.convertstring.com/en/Hash/SHA256: it seems ok.

The full code, with an example of usage, is here: https://github.com/jsfan3/SHA-Codename-One

Inside the Javadoc @author, I gave credits to Johan Stenberg: I took him code and I only sligthly modified it to adapt it to the Codename One API.

That's all. If you think that it can be useful for other people, you can evaluate if you want to integrate this code in the Codename One API, for example in StringUtil or elsewhere.

codenameone commented 5 years ago

We specifically avoided these functions so we wouldn't need to go through export control regulations. Our bouncy castle cn1lib has support for SHA but I think it's only SHA1 so this might be a nice addition there https://github.com/codenameone/bouncy-castle-codenameone-lib/ I would like to add a more "user friendly" API to that cn1lib as it's pretty hard to use.