0N/A/*
2362N/A * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.crypto.spec;
0N/A
0N/Aimport java.security.spec.AlgorithmParameterSpec;
0N/A
0N/A/**
0N/A * This class specifies an <i>initialization vector</i> (IV).
0N/A * Examples which use IVs are ciphers in feedback mode,
0N/A * e.g., DES in CBC mode and RSA ciphers with OAEP encoding
0N/A * operation.
0N/A *
0N/A * @author Jan Luehe
0N/A *
0N/A * @since 1.4
0N/A */
0N/Apublic class IvParameterSpec implements AlgorithmParameterSpec {
0N/A
0N/A private byte[] iv;
0N/A
0N/A /**
0N/A * Creates an IvParameterSpec object using the bytes in <code>iv</code>
0N/A * as the IV.
0N/A *
0N/A * @param iv the buffer with the IV. The contents of the
0N/A * buffer are copied to protect against subsequent modification.
0N/A * @throws NullPointerException if <code>iv</code> is <code>null</code>
0N/A */
0N/A public IvParameterSpec(byte[] iv) {
0N/A this(iv, 0, iv.length);
0N/A }
0N/A
0N/A /**
0N/A * Creates an IvParameterSpec object using the first <code>len</code>
0N/A * bytes in <code>iv</code>, beginning at <code>offset</code>
0N/A * inclusive, as the IV.
0N/A *
0N/A * <p> The bytes that constitute the IV are those between
0N/A * <code>iv[offset]</code> and <code>iv[offset+len-1]</code> inclusive.
0N/A *
0N/A * @param iv the buffer with the IV. The first <code>len</code>
0N/A * bytes of the buffer beginning at <code>offset</code> inclusive
0N/A * are copied to protect against subsequent modification.
0N/A * @param offset the offset in <code>iv</code> where the IV
0N/A * starts.
0N/A * @param len the number of IV bytes.
0N/A * @throws IllegalArgumentException if <code>iv</code> is <code>null</code>
0N/A * or <code>(iv.length - offset < len)</code>
0N/A * @throws ArrayIndexOutOfBoundsException is thrown if <code>offset</code>
0N/A * or <code>len</code> index bytes outside the <code>iv</code>.
0N/A */
0N/A public IvParameterSpec(byte[] iv, int offset, int len) {
0N/A if (iv == null) {
0N/A throw new IllegalArgumentException("IV missing");
0N/A }
0N/A if (iv.length - offset < len) {
0N/A throw new IllegalArgumentException
0N/A ("IV buffer too short for given offset/length combination");
0N/A }
0N/A if (len < 0) {
0N/A throw new ArrayIndexOutOfBoundsException("len is negative");
0N/A }
0N/A this.iv = new byte[len];
0N/A System.arraycopy(iv, offset, this.iv, 0, len);
0N/A }
0N/A
0N/A /**
0N/A * Returns the initialization vector (IV).
0N/A *
0N/A * @return the initialization vector (IV). Returns a new array
0N/A * each time this method is called.
0N/A */
0N/A public byte[] getIV() {
0N/A return (byte[])this.iv.clone();
0N/A }
0N/A}