Questions tagged [spongycastle]

a repackage of the Bouncy Castle Java cryptographic libraries, targeted specificlly at Android

The Android platform unfortunately ships with a cut-down version of Bouncy Castle - as well as being crippled, it also makes installing an updated version of the libraries difficult due to classloader conflicts.

Spongy Castle is the stock Bouncy Castle libraries with a couple of small changes to make it work on Android:

  • all package names have been moved from org.bouncycastle.* to org.spongycastle.* - to avoid classloader conflicts the Java Security
  • API Provider name is now SC rather than BC no class names change, so
  • the BouncyCastleProvider class remains Bouncy, not Spongy, but moves to the org.spongycastle.jce.provider package.

In general Spongy Castle should be a drop-in replacement for Bouncy Castle, but there are a couple of pain points:

  • ProGuard can often remove crucial classes from the Spongy Castle libs (internally, Bouncy Castle uses a lot of class-loading-by-name, which means ProGuard will over-aggressively remove it's classes). ProGuard config must be tweaked to keep the appropriate classes for whatever crypto algorithms you need.
  • Not all classes from Oracle Java are present on Android - for example, missing AWT classes block usage of the S/MIME API.
119 questions
29
votes
3 answers

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…
Nathan Fig
  • 14,970
  • 9
  • 43
  • 57
11
votes
1 answer

Generating PublicKey from x and y values of elliptic curve point

I am trying to generate a shared secret in my app like this: public static byte[] generateSharedSecret(PrivateKey privateKey PublicKey publicKey) { KeyAgreement keyAgreement = KeyAgreement.getInstance("ECDH", "SC"); …
Datenshi
  • 1,191
  • 5
  • 18
  • 56
9
votes
1 answer

Are there advantages for using SpongyCastle over BouncyCastle, if targeting Android 3.0 and later?

If I understand the situation correctly, SpongyCastle is a renaming of BouncyCastle and it was created to give people the ability to include a new version of BouncyCastle on Android, since just including the latest BouncyCastle jar would cause…
7
votes
1 answer

Can't initialise keystore on Samsung android

EDIT: I have now seen this error on a non-Samsung KitKat 4.4.3 device (Gigabyte/Zebra TC55). I am trying to initialise a null KeyStore in my custom X509TrustManager class. In the constructor, I do the following: public EasyX509TrustManager(KeyStore…
eoinzy
  • 2,152
  • 4
  • 36
  • 67
7
votes
1 answer

Spongy Castle RSA Encryption/Decryption with Android Keystore

Attempting to use SpongyCastle to provide the preferred encryption algorithm of RSA/ECB/OAEPwithSHA-512andMGF1Padding for Asymmetric encryption/decryption tasks on all supported Android device versions and having issues. Encryption appears to be…
7
votes
1 answer

Dealing with duplicate entries in AndroidStudio: java.util.zip.ZipException

EDIT: Solution from Error: java.util.zip.ZipException: duplicate entry doesn't work here, because I don't have problem with support-v4 module I'm trying to build an Android project which uses SpongyCastle, but unfortunately it requires javax.naming…
Naan
  • 521
  • 1
  • 11
  • 28
7
votes
2 answers

Export RSA public key to PEM String using java

So I'm using Spongy Castle (Android) to generate a PEM encoded string for an RSA public key that will be uploaded to a server. This is what I'm currently doing: PublicKey publicKey = keyPair.getPublic(); StringWriter writer = new…
fernandohur
  • 7,014
  • 11
  • 48
  • 86
6
votes
1 answer

Jsch with spongycastle rather than bouncycastle on Android

I currently have an Android application connecting to my router via ssh using a password. I'm looking to improve this so I can use keys but I am having real issues. From what I understand the version of bouncycastle included with android is a…
Fuzzy
  • 847
  • 9
  • 23
6
votes
1 answer

Create RSAPrivateKey from PEM encoded string

SO I have this code private static RSAPrivateKey buildRSAPrivateKey(String privateKey) { PEMReader pemReader = new PEMReader(new StringReader(privateKey)); try { KeyPair pair = (KeyPair) pemReader.readObject(); …
fernandohur
  • 7,014
  • 11
  • 48
  • 86
6
votes
3 answers

Compare PublicKey object in java

I have two PublicKey object.I want to compare both for equality or to check which is latest object using java security API or bouncy castle API.How can i achieve this?
Swapnil
  • 2,409
  • 4
  • 26
  • 48
6
votes
1 answer

Different RSA public key generated on Android

I was able to generate a public key in my Java desktop environment and I got something like this Sun RSA public key, 1024 bits modulus:…
5
votes
2 answers

Android Encrypting String using RSA Public key

I am working in a project where I have to encrypt password using RSA public key. I tried many samples and solutions from SO like as follows Android RSA encryption from public string RSA using SpongyCastle But none of the solutions worked in my…
Chandru
  • 5,954
  • 11
  • 45
  • 85
5
votes
1 answer

Using Spongycastle with Proguard

I've been strugling with proguard to make Spongycastle work. Most of the time, the problem comes when I'm exporting a signed APK, either I've got error, or the app will just crash before starting. So, I've managed to gather informations to get a…
Passeur
  • 71
  • 1
  • 6
5
votes
2 answers

Equivalent of spongycastle encryption for ios

This has stumped me - the following code uses SpongyCastle's encryption/decryption for Android - I am trying to achieve cross-platform encryption/decryption for iOS. The following code (from Android) works a treat, AES 128bit CBC with PKCS7Padding,…
t0mm13b
  • 34,087
  • 8
  • 78
  • 110
4
votes
0 answers

Generating CSR using Android KeyStore keys

Is there a way of generating CSRs of keys stored inside an Android KeyStore? I know you can generate keys then generate a CSR and lastly store the keys inside the Android KeyStore, but is it also possible to generate CSRs of at an earlier point…
C3nturyFox
  • 41
  • 1
1
2 3 4 5 6 7 8