SecretKeySpecpublic class SecretKeySpec extends Object implements SecretKey, Serializable, KeySpecA key specification for a SecretKey and also a secret key
implementation that is provider-independent. It can be used for raw secret
keys that can be specified as byte[] . |
Fields Summary |
---|
private static final long | serialVersionUID | private final byte[] | key | private final String | algorithm | private final String | format |
Constructors Summary |
---|
public SecretKeySpec(byte[] key, String algorithm)Creates a new SecretKeySpec for the specified key data and
algorithm name. //$NON-NLS-1$
if (key == null) {
throw new IllegalArgumentException(Messages.getString("crypto.05")); //$NON-NLS-1$
}
if (key.length == 0) {
throw new IllegalArgumentException(Messages.getString("crypto.35")); //$NON-NLS-1$
}
if (algorithm == null) {
throw new IllegalArgumentException(Messages.getString("crypto.02")); //$NON-NLS-1$
}
this.algorithm = algorithm;
this.key = new byte[key.length];
System.arraycopy(key, 0, this.key, 0, key.length);
| public SecretKeySpec(byte[] key, int offset, int len, String algorithm)Creates a new SecretKeySpec for the key data from the
specified buffer key starting at offset with
length len and the specified algorithm name.
if (key == null) {
throw new IllegalArgumentException(Messages.getString("crypto.05")); //$NON-NLS-1$
}
if (key.length == 0) {
throw new IllegalArgumentException(Messages.getString("crypto.35")); //$NON-NLS-1$
}
// BEGIN android-changed
if (len < 0 || offset < 0) {
throw new ArrayIndexOutOfBoundsException(Messages.getString("crypto.36")); //$NON-NLS-1$
}
// END android-changed
if ((key.length - offset < len)) {
throw new IllegalArgumentException(Messages.getString("crypto.37")); //$NON-NLS-1$
}
if (algorithm == null) {
throw new IllegalArgumentException(Messages.getString("crypto.02")); //$NON-NLS-1$
}
this.algorithm = algorithm;
this.key = new byte[len];
System.arraycopy(key, offset, this.key, 0, len);
|
Methods Summary |
---|
public boolean | equals(java.lang.Object obj)Compares the specified object with this SecretKeySpec
instance.
if (obj == this) {
return true;
}
if (!(obj instanceof SecretKeySpec)) {
return false;
}
SecretKeySpec ks = (SecretKeySpec) obj;
return (algorithm.equalsIgnoreCase(ks.algorithm))
&& (Arrays.equals(key, ks.key));
| public java.lang.String | getAlgorithm()Returns the algorithm name.
return algorithm;
| public byte[] | getEncoded()Returns the encoded form of this secret key.
byte[] result = new byte[key.length];
System.arraycopy(key, 0, result, 0, key.length);
return result;
| public java.lang.String | getFormat()Returns the name of the format used to encode the key.
return format;
| public int | hashCode()Returns the hash code of this SecretKeySpec object.
int result = algorithm.length();
for (byte element : key) {
result += element;
}
return result;
|
|