FileDocCategorySizeDatePackage
RC2ParameterSpec.javaAPI DocAndroid 1.5 API5578Wed May 06 22:41:02 BST 2009javax.crypto.spec

RC2ParameterSpec

public class RC2ParameterSpec extends Object implements AlgorithmParameterSpec
The algorithm parameter specification for the RC2 algorithm.
since
Android 1.0

Fields Summary
private final int
effectiveKeyBits
private final byte[]
iv
Constructors Summary
public RC2ParameterSpec(int effectiveKeyBits)
Creates a new RC2ParameterSpec instance with the specified effective key length (in bits),

param
effectiveKeyBits the effective key length (in bits).

        this.effectiveKeyBits = effectiveKeyBits;
        iv = null;
    
public RC2ParameterSpec(int effectiveKeyBits, byte[] iv)
Creates a new RC2ParameterSpec instance with the specified effective key length (in bits) and initialization vector.

The size of the initialization vector must be at least 8 bytes which are copied to protect them against modification.

param
effectiveKeyBits the effective key length (in bits).
param
iv the initialization vector.
throws
IllegalArgumentException if the initialization vector is null or shorter than 8 bytes.

        if (iv == null) {
            throw new IllegalArgumentException(Messages.getString("crypto.31")); //$NON-NLS-1$
        }
        if (iv.length < 8) {
            throw new IllegalArgumentException(Messages.getString("crypto.41")); //$NON-NLS-1$
        }
        this.effectiveKeyBits = effectiveKeyBits;
        this.iv = new byte[8];
        System.arraycopy(iv, 0, this.iv, 0, 8);
    
public RC2ParameterSpec(int effectiveKeyBits, byte[] iv, int offset)
Creates a new RC2ParameterSpec instance with the specified effective key length (in bits) and initialization vector.

The size of the initialization vector starting at offset must be at least 8 bytes which are copied to protect them against modification.

param
effectiveKeyBits the effective key length (in bits).
param
iv the initialization vector.
param
offset the offset in the initialization vector to start at.
throws
IllegalArgumentException if the initialization vector is null or starting at offset is shorter than 8 bytes.

        if (iv == null) {
            throw new IllegalArgumentException(Messages.getString("crypto.31")); //$NON-NLS-1$
        }
        if (iv.length - offset < 8) {
            throw new IllegalArgumentException(Messages.getString("crypto.41")); //$NON-NLS-1$
        }
        this.effectiveKeyBits = effectiveKeyBits;
        this.iv = new byte[8];
        System.arraycopy(iv, offset, this.iv, 0, 8);
    
Methods Summary
public booleanequals(java.lang.Object obj)
Compares the specified object to this RC2ParameterSpec instance.

param
obj the object to compare.
return
true if the effective key length and the initialization vector of both objects are equal, otherwise false.

        if (obj == this) {
            return true;
        }
        if (!(obj instanceof RC2ParameterSpec)) {
            return false;
        }
        RC2ParameterSpec ps = (RC2ParameterSpec) obj;
        return (effectiveKeyBits == ps.effectiveKeyBits)
            && (Arrays.equals(iv, ps.iv));
    
public intgetEffectiveKeyBits()
Returns the effective key length (in bits).

return
the effective key length (in bits).

        return effectiveKeyBits;
    
public byte[]getIV()
Returns a copy of the initialization vector.

return
a copy of the initialization vector, or null if none specified.

        if (iv == null) {
            return null;
        }
        byte[] result = new byte[iv.length];
        System.arraycopy(iv, 0, result, 0, iv.length);
        return result;
    
public inthashCode()
Returns the hash code of this RC2ParameterSpec instance.

return
the hash code.

        int result = effectiveKeyBits;
        if (iv == null) {
            return result;
        }
        for (byte element : iv) {
            result += element;
        }
        return result;