Code example for SecureRandom

Methods: nextBytes

0
    /** 
     * Generates a random initialisation vector. 
     * @return A random initialisation vector. 
     */ 
    public byte[] getIv() { 
        SecureRandom sr = new SecureRandom();
        byte[] iv = new byte[IV_BYTES];
        sr.nextBytes(iv);
        return iv;
    } 
 
    /** 
     * Generates a random salt. 
     * @return A random salt. 
     */ 
    public byte[] getSalt() { 
        SecureRandom sr = new SecureRandom();
        byte[] salt = new byte[SALT_BYTES];
        sr.nextBytes(salt);
        return salt;
    }