package javax.crypto.spec;
import java.security.spec.AlgorithmParameterSpec;
/**
* This class specifies an initialization vector (IV). IVs are used
* by ciphers in feedback mode, e.g., DES in CBC mode.
*/
public class IvParameterSpec
implements AlgorithmParameterSpec
{
private byte[] iv;
/**
* Uses the bytes in iv
as the IV.
*
* @param iv the buffer with the IV
*/
public IvParameterSpec(
byte[] iv)
{
if (iv == null)
{
throw new IllegalArgumentException("null iv passed");
}
this.iv = new byte[iv.length];
System.arraycopy(iv, 0, this.iv, 0, iv.length);
}
/**
* Uses the first len
bytes in iv
,
* beginning at offset
inclusive, as the IV.
*
* The bytes that constitute the IV are those between
* iv[offset]
and iv[offset+len-1]
inclusive.
*
* @param iv the buffer with the IV
* @param offset the offset in iv
where the IV starts
* @param len the number of IV bytes
*/
public IvParameterSpec(
byte[] iv,
int offset,
int len)
{
if (iv == null)
{
throw new IllegalArgumentException("Null iv passed");
}
if (offset < 0 || len < 0 || (iv.length - offset) < len)
{
throw new IllegalArgumentException("Bad offset/len");
}
this.iv = new byte[len];
System.arraycopy(iv, offset, this.iv, 0, len);
}
/**
* Returns the initialization vector (IV).
*
* @return the initialization vector (IV)
*/
public byte[] getIV()
{
byte[] tmp = new byte[iv.length];
System.arraycopy(iv, 0, tmp, 0, iv.length);
return tmp;
}
}