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
1
vote
1 answer

Why doesn't Google Cloud Key Management Service's Java client library support Android?

It is documented as not supporting Android. Why? Is it just because Android's BouncyCastle's implementation is shrunk down on features and doesn't support things like KeyPairGenerator/ECDSA (Elliptic Curve Digital Signature Algorithm)? (Here's…
Vrakfall
  • 966
  • 7
  • 13
1
vote
0 answers

Spongycastle Signature.sign() returns null

Using com.madgag.spongycastle:pkix:1.54.0.0 on Android 7.0 byte[] testData = "test data".getBytes("UTF_8"); Signature sign = Signature.getInstance("SHA256withRSA"); sign.initSign(privateKey); sign.update(testData); byte[] signature =…
Oleksandr
  • 3,761
  • 8
  • 50
  • 80
1
vote
0 answers

Illegal Key Size using AES/CBC/PKCS5Padding and Spongycastle on Android Studio

Attempting 256 bit AES crypto on Android Studio. Developed a unit test to run using Android Studio 3.0.1. JDK does have the upgraded local and USExport policy files. Same code is used for 128 bit AES/CBC/PKCS5Padding, and works without error. Key…
NDK
  • 41
  • 5
1
vote
0 answers

java.lang.NoClassDefFoundError: org.spongycastle.util.io.pem.PemWriter

I am using spongy castle library and it works well on API 16+. But I get this error on api level<16; java.lang.NoClassDefFoundError: org.spongycastle.util.io.pem.PemWriter I added reference like below; compile…
oyenigun
  • 587
  • 6
  • 15
1
vote
1 answer

Base64 encode/decode in ECC encrypt and decrypt

I want to test the ECC algorithm encrypt and decrypt. I write code to: Generate key pair (publickey and privatekey) ---> write them to file (maybe not secure but I just only test). Then using public key to encrypt my string (Write on Java) Now, I…
ThanhLam112358
  • 878
  • 1
  • 20
  • 51
1
vote
1 answer

Install AndroidKeyStore entry to AndroidCAStore

I use Android application to generate KeyPair, create CSR and send it to my CA. During keyPair generation i use "AndroidKeyStore": KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA","AndroidKeyStore"); …
macieg_b
  • 165
  • 3
  • 15
1
vote
1 answer

Does SpongyCastle support DERObject class?

I'm attempting to use the equivalent of the following class in an Android application, where I'm using Spongy Castle 1.54: org.bouncycastle.asn1.DERObject I cannot import org.spongycastle.asn1.DERObject, nor does the BouncyCastle API reference list…
Wesley Bunton
  • 135
  • 1
  • 11
1
vote
1 answer

SpongyCastle private key extraction very slow

I am using following method to extract private key from secret key using Spongy Castle: public static PGPPrivateKey findPrivateKey(PGPSecretKey pgpSecKey, char[] pass) throws PGPException { if (pgpSecKey == null) return null; …
horin
  • 1,664
  • 6
  • 23
  • 52
1
vote
1 answer

Generating valid ECDSA secp256r1/prime256v1 key pair on Android, using Spongy Castle (Bouncy Castle distribution)

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
1
vote
1 answer

How to generate same type of ecdsa keypair in java as generated by openssl?

I am executing the following command to generate ecdsa keypair on my machine: openssl ecparam -genkey -name secp256k1 -noout -outform DER -out private.key and on executing this next command openssl ec -inform DER -in private.key -noout -text, I get…
Harry
  • 1,151
  • 11
  • 27
1
vote
1 answer

Add spongycastle as provider to Android Studio

I have tried to add SpongyCastle as a library to my project so I can use DH for key exchange. However, in Android Studio 2.0, I can't add it as a provider. I have followed the instructions of adding as a library and then adding the…
Jooba0352
  • 135
  • 1
  • 13
1
vote
1 answer

Android Authenticator STORE A CRYPTOGRAPHICALLY SECURE TOKEN

I am authenticating using spongeycastle PKCS10CertificationRequest CSR to a RESTful Certificate Authority. I'm considering using Android Authenticator. According to:…
JDOaktown
  • 4,262
  • 7
  • 37
  • 52
1
vote
1 answer

Spongey Castle self-signed Certificate vs. Android KeyStore?

I'm trying to create a self-signed certificate. I want to do this in order to store a Spongey Castle KeyPair into "AndroidKeyStore". The signature needs to be ECDSA for P-256 with a SHA-256 digest. // see…
JDOaktown
  • 4,262
  • 7
  • 37
  • 52
1
vote
0 answers

Serpent GCM bouncy castle implementation is very slow on Android

I used latest sources of Bouncy Castle to implement Serpent GCM encryption. public byte[] encrypt(byte[] key, byte[] iv, byte[] pt, byte[] aad, int tagLength) throws InvalidCipherTextException { GCMBlockCipher c = new GCMBlockCipher(new…
Vitaly
  • 43
  • 1
  • 6
1
vote
1 answer

Can KeyAgreement be used without AlgorithmParameterSpec?

In my Android application working with SpongyCastle, I want to perform ECDH Key Exchange using a specific elliptic curve (prime192v1) and I am using this code to generate byte[] representation of private and public params: try{ …
michnovka
  • 2,880
  • 3
  • 26
  • 58