public class SecretKey
extends javax.crypto.spec.SecretKeySpec
SecretKey
,
Key
,
KeyGenerator
,
Serialized FormConstructor and Description |
---|
SecretKey(byte[] key,
int off,
int len,
java.lang.String algName)
Creates a SecretKey object from given byte sub-array and algorithm name.
|
SecretKey(byte[] key,
java.lang.String algName)
Creates a SecretKey object from given byte array and algorithm name.
|
SecretKey(javax.crypto.SecretKey key) |
Modifier and Type | Method and Description |
---|---|
void |
destroyCriticalData()
Destroys the critical data of this object.
|
boolean |
equals(java.lang.Object obj)
Compares two secret keys.
|
java.lang.String |
getAlgorithm()
Returns the name of the key algorithm for this key.
|
byte[] |
getEncoded()
Returns a copy of the secret key as byte array.
|
java.lang.String |
getFormat()
Returns the format name.
|
int |
hashCode()
Returns a hash code value for this object.
|
void |
setAlgorithm(java.lang.String algorithm)
Sets the algorithm name of this secret key.
|
java.lang.String |
toString()
Returns a string representation of this SecretKey.
|
public SecretKey(byte[] key, java.lang.String algName)
This constructor is called from inside a KeyGenerator to create a
SecretKey. Applications shall use the KeyGenerator.getInstance
and generateKey
methods for creating a SecretKey object.
key
- the key as byte arrayalgName
- the name of the key algorithmKeyGenerator.getInstance(java.lang.String)
,
KeyGenerator.generateKey()
public SecretKey(byte[] key, int off, int len, java.lang.String algName)
off
, only len
bytes of the given
key
byte array are used for creating the SecretKey.
This constructor is called from inside a KeyGenerator to create a
SecretKey. Applications shall use the KeyGenerator.getInstance
and generateKey
methods for creating a SecretKey object.
key
- the key as byte arrayalgName
- the name of the key algorithmKeyGenerator.getInstance(java.lang.String)
,
KeyGenerator.generateKey()
public SecretKey(javax.crypto.SecretKey key) throws java.security.InvalidKeyException
java.security.InvalidKeyException
public byte[] getEncoded()
getEncoded
in interface java.security.Key
getEncoded
in class javax.crypto.spec.SecretKeySpec
public java.lang.String getAlgorithm()
getAlgorithm
in interface java.security.Key
getAlgorithm
in class javax.crypto.spec.SecretKeySpec
public void setAlgorithm(java.lang.String algorithm)
algorithm
- the name of the algorithm for this keypublic java.lang.String getFormat()
getFormat
in interface java.security.Key
getFormat
in class javax.crypto.spec.SecretKeySpec
public void destroyCriticalData()
public boolean equals(java.lang.Object obj)
equals
in class javax.crypto.spec.SecretKeySpec
obj
- an object to be compared with this pointpublic int hashCode()
hashCode
in class javax.crypto.spec.SecretKeySpec
public java.lang.String toString()
toString
in class java.lang.Object