所需的图书馆的Android海绵城堡档案

时间:2011-12-05 19:07:32

标签: android

我正在尝试将spongy castle添加到我的android项目中,但我总是收到以下错误: 在项目'xxx'中存档所需的库'lib / scprov-jdk15-1.46.99.3-UNOFFICIAL-ROBERTO-RELEASE.jar'无法读取或不是有效的ZIP文件。

我已阅读How to include the Spongy Castle JAR in Android?并尝试找出https://github.com/rtyley/spongycastle-eclipse与我的项目之间的区别,但我找不到任何内容。

1 个答案:

答案 0 :(得分:3)

我不确定是否为时已晚,但要将BountyCastle添加到您的项目中,只需将其添加到您要进行加密的类中:

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

以下是一个例子:

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] + " ");
    }

}
}

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