2011-12-05 30 views

回答

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