It can be used to construct a SecretKey from a byte array,
without having to go through a (provider-based)
SecretKeyFactory.
This class is only useful for raw secret keys that can be represented as a byte array and have no key parameters associated with them, e.g., DES or Triple DES keys.
javax.crypto.SecretKey , javax.crypto.SecretKeyFactory
| Modifier and Type | Field and Description |
|---|---|
| private final String | algorithm
The name of the algorithm associated with this key. |
| private byte[] | key
The secret key. |
| private static final long |
| Access | Constructor and Description |
|---|---|
| public | SecretKeySpec(byte[]
the key material of the secret key. The contents of
the array are copied to protect against subsequent modification. key, String the name of the secret key algorithm to be associated
with the given key material.
See the SecretKey Algorithms section in the
Java Security Standard Algorithm Names Specification
for information about standard secret key algorithm names. algorithm)Constructs a secret key from the given byte array. |
| public | SecretKeySpec(byte[]
the key material of the secret key. The first
key, int len bytes of the array beginning at
offset inclusive are copied to protect
against subsequent modification.the offset in offset, int key where the key material
starts.the length of the key material. len, String the name of the secret key algorithm to be associated
with the given key material.
See the SecretKey Algorithms section in the
Java Security Standard Algorithm Names Specification
for information about standard secret key algorithm names. algorithm)Constructs a secret key from the given byte array, using the first
|
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| private static String | |
| public boolean | Returns: true if the objects are considered equal, false ifobj is null or otherwise.the object to test for equality with this object. obj)Overrides java. Tests for equality between the specified object and this object. |
| public String | Returns: the secret key algorithm.Implements java. Returns the name of the algorithm associated with this secret key. |
| public byte[] | Returns: the key material. Returns a new array each time this method is called.Implements java. Returns the key material of this secret key. |
| public String | Returns: the string "RAW".Implements java. Returns the name of the encoding format for this secret key. |
| public int | |
| private void | readObject(ObjectInputStream
the stream)ObjectInputStream from which data is readRestores the state of this object from the stream. |
| algorithm | back to summary |
|---|---|
| private final String algorithm The name of the algorithm associated with this key. | |
| key | back to summary |
|---|---|
| private byte[] key The secret key. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides javax. | |
| SecretKeySpec | back to summary |
|---|---|
| public SecretKeySpec(byte[] key, String algorithm) Constructs a secret key from the given byte array. This constructor does not check if the given bytes indeed specify a
secret key of the specified algorithm. For example, if the algorithm is
DES, this constructor does not check if
| |
| SecretKeySpec | back to summary |
|---|---|
| public SecretKeySpec(byte[] key, int offset, int len, String algorithm) Constructs a secret key from the given byte array, using the first
The bytes that constitute the secret key are
those between This constructor does not check if the given bytes indeed specify a
secret key of the specified algorithm. For example, if the algorithm is
DES, this constructor does not check if
| |
| clear | back to summary |
|---|---|
| pack-priv void clear() Clear the key bytes inside. | |
| doSanityCheck | back to summary |
|---|---|
| private static String doSanityCheck(byte[] key, String algorithm) | |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Tests for equality between the specified object and this object. Two SecretKeySpec objects are considered equal if they are both SecretKey instances which have the same case-insensitive algorithm name and key encoding. | |
| getAlgorithm | back to summary |
|---|---|
| public String getAlgorithm() Implements java. Returns the name of the algorithm associated with this secret key.
| |
| getEncoded | back to summary |
|---|---|
| public byte[] getEncoded() Implements java. Returns the key material of this secret key.
| |
| getFormat | back to summary |
|---|---|
| public String getFormat() Implements java. Returns the name of the encoding format for this secret key.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Calculates a hash code value for the object. Objects that are equal will also have the same hashcode.
| |
| readObject | back to summary |
|---|---|
| private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException Restores the state of this object from the stream.
| |