2

I'm trying to add spongy castle to my android project, but I always get the following error: Archive for required library 'lib/scprov-jdk15-1.46.99.3-UNOFFICIAL-ROBERTO-RELEASE.jar' in project 'xxx' cannot be read or is not a valid ZIP file.

I've read How to include the Spongy Castle JAR in Android? and tried to find the difference between https://github.com/rtyley/spongycastle-eclipse and my project, but I don't find anything.

Community
  • 1
  • 1

1 Answers1

3

I'm not sure if it is too late, but to add BountyCastle to your project, you simply add this to the class that your going to be doing encryption in:

static {
     Security.addProvider(new org.spongycastle.jce.provider.BouncyCastleProvider());
}

Here is an example:

import java.security.SecureRandom;
import java.security.Security;


public class SHA1PRNG {
 //here i swapped out the bountycastle provider and used the spongycatle
   static {
      Security.addProvider(new org.spongycastle.jce.provider.BouncyCastleProvider());
}

public static void main(String[] args) throws Exception {

    SecureRandom rng = SecureRandom.getInstance("SHA1PRNG");
    rng.setSeed(711);

    int numberToGenerate = 999;
    byte randNumbers[] = new byte[numberToGenerate];

    rng.nextBytes(randNumbers);
    for(int j=0; j<numberToGenerate; j++) {
        System.out.print(randNumbers[j] + " ");
    }

}
}

From: www.java2s.com/Code/Java/Security/SecureRandomSHA1PRNG.htm

Jared Burrows
  • 54,294
  • 25
  • 151
  • 185