Java IV Generate generateIV()

Here you can find the source of generateIV()

Description

Randomly generates an initialization vector (IV) which can be used as parameter for symmetric encryption.

License

Open Source License

Return

Returns a randomly generated IV.

Declaration

public static byte[] generateIV() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.security.SecureRandom;

public class Main {
    private static final int IV_LENGTH = 16;

    /**/*from   w  ww . j ava 2  s.c om*/
     * Randomly generates an initialization vector (IV) which can be used as parameter for symmetric
     * encryption.
     * 
     * @return Returns a randomly generated IV.
     */
    public static byte[] generateIV() {
        SecureRandom random = new SecureRandom();
        byte[] iv = new byte[IV_LENGTH];
        do {
            random.nextBytes(iv);
        } while (iv[0] == 0);
        return iv;
    }
}

Related

  1. generateIV()
  2. generateIV()
  3. generateIV()
  4. generateIV()
  5. generateIV(byte[] iv)