user1029309
user1029309

Reputation:

Android spongy castle archive for required library

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.

Upvotes: 2

Views: 1784

Answers (1)

Jared Burrows
Jared Burrows

Reputation: 55535

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

Upvotes: 3

Related Questions