I use bouncycastle to read the PKCS#1 format RSA public key, this key is begin with:
-----BEGIN RSA PUBLIC KEY----
The code works well, but it will depends on a heavy bouncycastle jar. It will cause the code can't be compiled on Android because of the java function's number is more than 65535.
I have changed the bouncycastle to spongycastle and decouple the prov.jar & pkix.jar. Also only use one class to reduce the code reference:
org.spongycastle.asn1.pkcs.RSAPublicKey rsaPublicKey = org.spongycastle.asn1.pkcs.RSAPublicKey.getInstance(keyBytes);
But the classes.dex will still be 2MB larger.
So I'm looking up is there light weight api to do it? Or the algorithm to read PKCS#1 RSA public key will be easy to write?
P.S. Using Proguard won't resolve the problem at all , it will disable the debugger in IDE.
Here is some code I whipped out that shows how easy this is. You are definitely better off using a tried and tested library but this particular ASN.1 object is relatively simple: