Java 8 SecureRandom - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 SecureRandom class.

This code example shows how to use the following methods:
 
import java.security.SecureRandom; 
 
class SecureRandomHolder { 
    // class loading is atomic - this is a lazy & safe singleton to be used by this package 
    public static final SecureRandom INSTANCE = new SecureRandom(); 
} 
9
CodeRank
This code example shows how to use the following methods:
 *  
 * @author calvin 
 */ 
public class Identities { 
 
	private static SecureRandom random = new SecureRandom();
 
	/** 
	 * 封装JDK自带的UUID, 通过Random数字生成, 中间有-分割. 
	 */ 
	public static String uuid() {
		return UUID.randomUUID().toString();
	} 
 
	/** 
	 * 封装JDK自带的UUID, 通过Random数字生成, 中间无-分割. 
	 */ 
	public static String uuid2() {
		return UUID.randomUUID().toString().replaceAll("-", "");
	} 
9
CodeRank
This code example shows how to use the following methods:generateSeed, getProvider, nextBytes, setSeed
 
    private void test_SecureRandom(SecureRandom sr) throws Exception {
        byte[] out1 = new byte[20];
        byte[] out2 = new byte[20];
 
        sr.nextBytes(out1);
        sr.nextBytes(out2);
        assertFalse(Arrays.equals(out1, out2));
 
        byte[] seed1 = sr.generateSeed(20);
        byte[] seed2 = sr.generateSeed(20);
        assertFalse(Arrays.equals(seed1, seed2));
 
        sr.setSeed(STATIC_SEED_BYTES);
        sr.nextBytes(out1);
        sr.nextBytes(out2);
        assertFalse(Arrays.equals(out1, out2));
 
        sr.setSeed(STATIC_SEED_LONG);
        sr.nextBytes(out1);

8
CodeRank
This code example shows how to use the following methods:
        { 
            super("RSA"); 
 
            engine = new RSAKeyPairGenerator();
            param = new RSAKeyGenerationParameters(defaultPublicExponent,
                            new SecureRandom(), 2048, defaultTests);
            engine.init(param);
        } 
 
        public void initialize( 
            int             strength,
            SecureRandom    random)
        { 
            param = new RSAKeyGenerationParameters(defaultPublicExponent,
                            random, strength, defaultTests);
 
            engine.init(param);
        } 
 
        public void initialize( 
8
CodeRank
This code example shows how to use the following methods:
 *  
 * @author calvin 
 */ 
public class Identities { 
 
	private static SecureRandom random = new SecureRandom();
 
	/** 
	 * 封装JDK自带的UUID, 通过Random数字生成, 中间有-分割. 
	 */ 
	public static String uuid() {
		return UUID.randomUUID().toString();
	} 
 
	/** 
	 * 封装JDK自带的UUID, 通过Random数字生成, 中间无-分割. 
	 */ 
	public static String uuid2() {
		return UUID.randomUUID().toString().replaceAll("-", "");
	} 
8
CodeRank
This code example shows how to use the following methods:
import android.util.Log; 
 
public class Security { 
 
	private static HashSet<Long> knownNonces = new HashSet<Long>();
	private static final SecureRandom RANDOM = new SecureRandom();
	private static final String TAG = Security.class.getSimpleName();
 
	/** Generates a nonce (a random number used once). */ 
	public static long generateNonce() { 
		long nonce = RANDOM.nextLong();
		knownNonces.add(nonce);
		return nonce;
	} 
 
	public static boolean isNonceKnown(long nonce) {
		return knownNonces.contains(nonce);
	} 
 
	public static void removeNonce(long nonce) {
8
CodeRank
This code example shows how to use the following methods:
    return erasures; 
  } 
   */ 
 
  static Random getRandom() {
    return new SecureRandom(new byte[] {(byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF});
  } 
 
  /* 
  static void assertArraysEqual(int[] expected, 
                                int expectedOffset, 
                                int[] actual, 
                                int actualOffset, 
                                int length) { 
    for (int i = 0; i < length; i++) { 
      assertEquals(expected[expectedOffset + i], actual[actualOffset + i]); 
    } 
  } 
   */ 
 
8
CodeRank
This code example shows how to use the following methods:nextBytes
        } 
 
        if (param instanceof KeyParameter && ivSize != 0)
        { 
            iv = new byte[ivSize];
            random.nextBytes(iv);
            param = new ParametersWithIV(param, iv);
        } 
 
        switch (opmode)
        { 
        case Cipher.WRAP_MODE:
            wrapEngine.init(true, param);
            break; 
        case Cipher.UNWRAP_MODE:
            wrapEngine.init(false, param);
            break; 
        case Cipher.ENCRYPT_MODE:
        case Cipher.DECRYPT_MODE:
            throw new IllegalArgumentException("engine only valid for wrapping");
8
CodeRank
This code example shows how to use the following methods:
	protected BenchmarkTask createTask() { 
		return new SessionTask(); 
	} 
 
	public class SessionTask extends BenchmarkTask { 
		private SecureRandom random = new SecureRandom();
 
		@Override 
		protected void execute(final int requestSequnce) {
 
			int randomIndex = random.nextInt((int) loopCount);
			final String key = new StringBuilder().append(keyPrefix).append(taskSequence).append(":")
					.append(randomIndex).toString();
 
			jedisTemplate.execute(new JedisActionNoResult() {
				@Override 
				public void action(Jedis jedis) {
					Session session = new Session(key);
					session.setAttrbute("name", key);
					session.setAttrbute("seq", requestSequnce);
8
CodeRank
This code example shows how to use the following methods:nextBytes
	 */ 
	public static byte[] generateSalt(int numBytes) {
		Validate.isTrue(numBytes > 0, "numBytes argument must be a positive integer (1 or larger)", numBytes);
 
		byte[] bytes = new byte[numBytes];
		random.nextBytes(bytes);
		return bytes;
	} 
 
	/** 
	 * 对文件进行md5散列. 
	 */ 
	public static byte[] md5(InputStream input) throws IOException {
		return digest(input, MD5);
	} 
 
	/** 
	 * 对文件进行sha1散列. 
	 */ 
	public static byte[] sha1(InputStream input) throws IOException {
8
CodeRank

Related Java 8 SecureRandom Questions & Answers:

See Code Examples for Java 8 SecureRandom Methods: