Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include the Spongy Castle JAR in Android?

Apparently Spongy Castle is the Android alternative to using a full version of Bouncy Castle.

However, on importing the jar I'm getting all kinds of "cannot be resolved" errors because it relies on packages not included with Android, primarily javax.mail, javax.activation, and javax.awt.datatransfer.

So what's the best way around this? Responses to this question and this indicate those packages shouldn't be used at all, and this popular question doesn't even consider finding a way to get AWT back. So how is Spongy Castle relying on them? People are using Spongy Castle, right?

like image 749
Nathan Fig Avatar asked Aug 01 '11 13:08

Nathan Fig


People also ask

What is Spongycastle Android?

556. The Android alternative to using a full version of Bouncy Castle. The collection of APIs for the Android platform used in cryptography. Spongy Castle is the stock Bouncy Castle libraries with a couple of small changes to make it work on Android.

What is spongy castle?

Spongy Castle was created back in 2011 because the Android platform bundled an old, restricted subset of Bouncy Castle. Simply adding an updated version of Bouncy Castle to your app resulted in class-clashes and exceptions - so you needed a repackaged & renamed version, like Spongy Castle.


1 Answers

If you are using gradle, then you can just specify your dependencies in build.gradle file like this:

dependencies {      ....     compile 'com.madgag.spongycastle:core:1.54.0.0'     compile 'com.madgag.spongycastle:prov:1.54.0.0'     compile 'com.madgag.spongycastle:pkix:1.54.0.0'     compile 'com.madgag.spongycastle:pg:1.54.0.0'      } 

You can find out the latest version of the library here.

Don't forget to insert it as a security provider in your app.

    static {     Security.insertProviderAt(new org.spongycastle.jce.provider.BouncyCastleProvider(), 1); } 
like image 102
ua741 Avatar answered Sep 19 '22 14:09

ua741