3
votes

I have a small app that im making. It uses the external bouncy castle crypto API as i need to use the SHA1 hashing function it provides as the codename one API excludes the native java one.

Problem is i only use the SHA1digest class.

import org.bouncycastle.crypto.digests.SHA1Digest;

but after i build the API the codename one build system puts the whole API in the final .jar file. which is 1.8mb. Now i cant build or test the app as its over the 1mb limit.

is there any way to solve this problem ?

2

2 Answers

0
votes

We remove the redundant stuff in the final build but not at that stage. If you want to reduce the bouncy castle library size I suggest you don't use the cn1lib and instead copy the sources you need into your project: https://github.com/codenameone/bouncy-castle-codenameone-lib/

You can do that selectively and as the project fails to compile you can add the additional dependencies. I'm sure it will still be smaller than the current cn1lib.

0
votes

I've 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).

This class is fully compatible with Codename One, I tested it in Simulator, Android native, iOS native and Javascript.

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

I compared the outputs of this class with http://www.convertstring.com/en/Hash/SHA256: they are the same.

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

The size of the Java class is about 8 kbyte, this could solve your issue, if you remove the bouncy castle cn1lib and if you need only this class.