SecureRandom nextBytes - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for SecureRandom nextBytes method.

This code example shows how to use the following methods:nextBytes
	/** 
	 * 基于Base62编码的SecureRandom随机生成bytes. 
	 */ 
	public static String randomBase62(int length) {
		byte[] randomBytes = new byte[length];
		random.nextBytes(randomBytes);
		return Encodes.encodeBase62(randomBytes);
	} 
} 
8
CodeRank
This code example shows how to use the following methods:nextBytes
	/** 
	 * 基于Base62编码的SecureRandom随机生成bytes. 
	 */ 
	public static String randomBase62(int length) {
		byte[] randomBytes = new byte[length];
		random.nextBytes(randomBytes);
		return Encodes.encodeBase62(randomBytes);
	} 
} 
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: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
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);

7
CodeRank
This code example shows how to use the following methods:generateSeed, 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:nextBytes
	/** 
	 * 生成随机向量,默认大小为cipher.getBlockSize(), 16字节. 
	 */ 
	public static byte[] generateIV() { 
		byte[] bytes = new byte[DEFAULT_IVSIZE];
		random.nextBytes(bytes);
		return bytes;
	} 
} 
8
CodeRank
This code example shows how to use the following methods:nextBytes
        } 
    } 
 
    protected String generateSeriesData() {
        byte[] newSeries = new byte[seriesLength];
        random.nextBytes(newSeries);
        return new String(Base64.encode(newSeries));
    } 
 
    protected String generateTokenData() {
        byte[] newToken = new byte[tokenLength];
        random.nextBytes(newToken);
        return new String(Base64.encode(newToken));
    } 
 
    private void addCookie(PersistentRememberMeToken token, HttpServletRequest request, HttpServletResponse response) {
        setCookie(new String[] {token.getSeries(), token.getTokenValue()}, getTokenValiditySeconds(), request, response);
    } 
 
    /** 
7
CodeRank
This code example shows how to use the following methods:nextBytes
     */ 
    public byte[] generateKey() 
    { 
        byte[]  key = new byte[strength];
 
        random.nextBytes(key);
 
        return key;
    } 
} 
7
CodeRank
This code example shows how to use the following methods:nextBytes
 
  protected void init() { 
    try { 
      if (iv == null) {
        iv = new byte[getIvLength()];
        rng.nextBytes(iv);
      } 
      cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv));
    } catch (InvalidKeyException e) {
      throw new RuntimeException(e);
    } catch (InvalidAlgorithmParameterException e) {
      throw new RuntimeException(e);
    } 
    initialized = true;
  } 
 
} 
7
CodeRank

Related SecureRandom nextBytes Questions & Answers:

nextBytes Method Overview
Generates a user-specified number of random bytes.
See Code Examples for other Java 8 SecureRandom Methods: