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
3
votes
1 answer

Spongycastle is missing many algorithms when loaded on android

In this stackoverflow answer you can see a code to print all available providers and corresponding algorithms: How to find out what algorithm [ encryption ] are supported by my JVM? I am using latest version of spongycastle and when I ask to get the…
George Pligoropoulos
  • 2,919
  • 3
  • 33
  • 65
2
votes
1 answer

seeds.txt and usage.txt not generated for Proguard with Android Studio release build

I am building my Android app release build by enabling minifyEnabled and shrinkResources. I am using a library named spongycastle for cryptographic purposes. The problem I am facing is that the entire spongycastle code is being bundled with the apk…
Swapnil
  • 1,870
  • 2
  • 23
  • 48
2
votes
2 answers

Android Studio: Custom Writer Class extends BufferedWriter (PemWriter)

The following is an example of the class that I have to use. I've generalized the names to get at the concept rather than the my particular use. I'm trying to figure out how to use it. So, I can't change this part, only what's in my…
Adam Winter
  • 1,680
  • 1
  • 12
  • 26
2
votes
0 answers

SpongyCastle: Error while finalizing cipher

in an Android project I need to authenticate my app for an https connection. Using the following method I'm trying to decrypt my private key, provided by the server developers in a .pem file. I use SpongyCastle, and at the top of the same class…
tonidi
  • 155
  • 2
  • 12
2
votes
0 answers

Get ECKey from bytes (Spongycastle)

I'm trying to create an android app which can sign a String with an privatekey I got passed and 100% working on vb and php im really confused and tried everything to fix the issue!!! I'm kinda new to crypto and would like to get any help…
2
votes
2 answers

Signature SHA256WITHECDSA implementation not found

I'm working on a project that creates a PKI to get a certificate request in Android. Right now I'm using Spongycastle for it and It's working in Android 5 and up, but on 4.X it's showing me this: Signature SHA256WITHECDSA implementation not found …
Ranbeuer
  • 167
  • 3
  • 12
2
votes
1 answer

Android verify signature always returns false

I'm trying to verify some signed content using ECDSA and spongycastle. Here is the code I'm using to generate the keypair with the brainpoolP512t1 ec curve: public static KeyPair getKeyPairbrainpoolP512t1() throws Exception { KeyPairGenerator…
Joel Pou
  • 158
  • 2
  • 13
2
votes
1 answer

Supplied key (android.security.keystore.AndroidKeyStoreRSAPrivateKey) is not a RSAPrivateKey instance

I do "sign" operation and have the following code: KeyStore.PrivateKeyEntry privateKeyEntry = (KeyStore.PrivateKeyEntry)keyStore.getEntry(keyAlias, null); PrivateKey privateKey = privateKeyEntry.getPrivateKey(); signature =…
Sandra
  • 4,239
  • 10
  • 47
  • 80
2
votes
1 answer

Android PrivateKey to BouncyCastle PrivateKeyInfo?

I am trying to use Bouncy/SpongyCastle's OAEP encoding to decode some wrapped data. However, the SpongyCastle API for initialising the OAEPEncoding class requires CipherParameters. In my case, I'm trying to unwrap something using an Android…
Ivan Stanev
  • 133
  • 1
  • 11
2
votes
1 answer

Android: InvalidKeySpecException: encoded key spec not recognised

When I try to make RSA public key from string. I get exception mentioned below. I am trying to verify generated keys (string, using Swift) in Android. How to convert the string to private/public key? static PublicKey getRSAPublicKeyFromString…
Hoàng Hiệp
  • 43
  • 1
  • 5
2
votes
1 answer

Android Spongy Castle Gradle dependencies

I am new to cryptography. I want to use Spongy Castle to encrypt (AES) to a file and write it to the disk. Do I need all the four(4) dependencies in my .gradle file? compile 'com.madgag.spongycastle:core:1.51.0.0' compile…
georgeok
  • 5,321
  • 2
  • 39
  • 61
2
votes
1 answer

How to convert PEM public key to DER public key?

I receive a public key from my REST API which is encoded in PEM. Now, I need to change the encoding to DER in order to store it as a PublicKey object. However, unfortunately, I get the following error: java.lang.IllegalArgumentException: unknown…
user3475602
  • 1,217
  • 2
  • 21
  • 43
2
votes
2 answers

Android to server communication using SSL with Bouncy Castle

I understand this is something which is not so difficult but very unfortunately I am stuck here and fighting it since yesterday, I have followed this Mutual Authentication in Android tutorial, to place a keystore in resources and trying to connect…
SSH
  • 1,609
  • 2
  • 22
  • 42
2
votes
1 answer

Spongycastle provider not working on Android

I am trying to use Spongy Castle on my Android application. As per these instructions, I have added the jar files and then called this method to include provider. static { Security.insertProviderAt(new…
Omer Arshad
  • 520
  • 7
  • 16
2
votes
3 answers

Decrypting SJCL encrypted strings in Android

I've got a string that's been encrypted by SJCL server-side, and needs to be decrypted in Android using whatever libraries are available. I tried BouncyCastle, until I ran into the problem of not being able to generate a key from PBKDF2. Now I'm…
mlimb
  • 61
  • 5