Android中的Spongy Castle

时间:2012-03-12 05:10:51

标签: java android random

Spongy Castle是否提供“SHA1PRNG”算法的实现?我问这个是因为Bouncy Castle似乎没有提供“SHA1PRNG”算法的实现。

1 个答案:

答案 0 :(得分:1)

这个答案可能为时已晚,但是,这是一个实施的例子:

SpongyCastle应与BountyCastle相同,只适用于Android。

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