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
4
votes
2 answers

How can I generate a valid ECDSA EC key pair?

I am trying to generate ECDSA key pair using SpongyCastle in Android. This is the code: static { Security.insertProviderAt(new org.spongycastle.jce.provider.BouncyCastleProvider(), 1); } public static KeyPair generate() { …
snewtMs
  • 61
  • 1
  • 2
  • 6
4
votes
2 answers

Xamarin.Android binding Spongy Castle / Bouncy Castle

Anyone successfully bound SpongyCastle to Xamarin.Android? I bump into a bunch of warnings with my Metadata.xml in the binding project. So far I have:
chrisva
  • 625
  • 9
  • 17
4
votes
1 answer

Android SpongyCastle ECDH secp384r1 Key Size Incorrect

I am trying to used SpongyCastle on Android for ECDH secp384r1 Public/Private Key pair generation. The problem I an running into is, the keys that I am generating are way too big. The public key is 120 bytes and the private key is 194 bytes. There…
T. Colligan
  • 161
  • 1
  • 9
4
votes
2 answers

Adding additional authenticated data to AES-GCM on Android

I'm trying to add the additional authenticated data (AAD) to AES-GCM on Android. I see the Java 7 version of Cipher notes about using GCMParameterSpec and the updateAAD(...) method but given Android is Java 6 based I'm all out of ideas. I'm using…
scottyab
  • 23,621
  • 16
  • 94
  • 105
3
votes
1 answer

How to encrypt and decrypt a file using Spongy Castle for Android

I have a XML file stored on the SDCard. I need to perform encryption and decryption on the complete file as a unit. I have seen that Spongy Castle is a good library for the Encryption and Decryption for android. But, I could not find any cipher…
Rahul Kalidindi
  • 4,666
  • 14
  • 56
  • 92
3
votes
1 answer

Unlimited Strength Jce and Android

I'm using SpongyCastle (full implementation of BouncyCastle's crypto functions for Android) and I have a bks that contains a key of size 384. I'm trying to extract that key using the method KeyStore.getKey(alias, password) as you would any key in a…
Otra
  • 8,108
  • 3
  • 34
  • 49
3
votes
1 answer

IV for encryption conversion. Expected IV length of 16 but was 24

Can someone please tell me why I am getting this error message? Obviously it is some kind of conversion that I am missing expected IV length of 16 but was 24 To call it I use String encrypted = "E5ADDEB05D9D7B3925B7DE16B560D87C"; String sKey =…
flashc5
  • 307
  • 1
  • 6
  • 16
3
votes
0 answers

Computing EC PublicKey from Private Key with BC

In my program, I can successfully restore an EC private key from a PEM file using Spongy Castle (Bouncy Castle equivalent for Android). As the file does not contain the public key, I am trying to recompute the public key from the private key. I am…
3
votes
0 answers

Android verify CA signature in X.509 Certificate

I have a Root CA certificate and a User certificate that has been signed by the CA. Under Windows using Certutil or OpenSSL I can verify that the CA's signature on the User certificate signature is OK. Now I am trying to verify the same signature…
SamStef1
  • 31
  • 5
3
votes
1 answer

How to construct PrivateKey if you know the curve name & raw private key/point?

Requirement: For a given named-curve, send as little data as you can, so that receiver can construct EC PrivateKey. I am currently using BouncyCastle/SpongyCastle on Android. This is what I have understood till now. KeyPairGenerator keyGen =…
ua741
  • 1,446
  • 15
  • 28
3
votes
2 answers

Retrieve ECC Public Key from Base64 encoded string

I've been trying to create an instance of java.security.PublicKey using a Base64 encoded ECC public key. MainActivity.java @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); …
Ankit Popli
  • 2,809
  • 3
  • 37
  • 61
3
votes
1 answer

Java NoClassDefFoundError with DexGuard and spongycastle

I'm trying to get DexGuard running on a project I'm working on. I already have ProGuard running successfully with proguard-rules.pro. After running a DexGuard release built the app crashes with FATAL EXCEPTION: main Process: com.project.fr, PID:…
Aegis
  • 5,761
  • 2
  • 33
  • 42
3
votes
1 answer

Creating an Https connecion with Client Side Certificate from PKCS#10 with SpongyCastle

The goal I'm working on implementing communication with Client-Certificate. Step 1: Create a PKCS#10 request (CSR) and give it to the my server for signing. The server contacts passes the CSR to the CA, and the CA signs it, and returns a PKCS#7…
Felix
  • 1,034
  • 1
  • 9
  • 29
3
votes
1 answer

java.io.IOException: Wrong version of key store. using SpongyCastle

I am using Spongycastle and hoping to create a self signed certificate programmatically. When I run the code below in Android I get java.io.IOException: Wrong version of key store. I'm not sure what I'm doing wrong, I figured Spongycastle would be…
casolorz
  • 8,486
  • 19
  • 93
  • 200
3
votes
1 answer

Android - Where is the best place to place the "addProvider" / "Security.insertProviderAt" code line

I would like, in an Android application where is the best place to place the following piece of code: static { Security.insertProviderAt(new org.spongycastle.jce.provider.BouncyCastleProvider(), 1); // Security.addProvider(new…
Jorge Gil
  • 4,265
  • 5
  • 38
  • 57