SecretKeySpec (Java SE 15 & JDK 15) (original) (raw)

All Implemented Interfaces:

[Serializable](../../../java/io/Serializable.html "interface in java.io"), [Key](../../../java/security/Key.html "interface in java.security"), [KeySpec](../../../java/security/spec/KeySpec.html "interface in java.security.spec"), [SecretKey](../SecretKey.html "interface in javax.crypto"), [Destroyable](../../security/auth/Destroyable.html "interface in javax.security.auth")


public class SecretKeySpec extends Object implements KeySpec, SecretKey

This class specifies a secret key in a provider-independent fashion.

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.

Since:

1.4

See Also:

SecretKey, SecretKeyFactory, Serialized Form

Constructors

Constructor Description
SecretKeySpec​(byte[] key, int offset, int len,String algorithm) Constructs a secret key from the given byte array, using the firstlen bytes of key, starting atoffset inclusive.
SecretKeySpec​(byte[] key,String algorithm) Constructs a secret key from the given byte array.
Modifier and Type Method Description
boolean equals​(Object obj) Tests for equality between the specified object and this object.
String getAlgorithm() Returns the name of the algorithm associated with this secret key.
byte[] getEncoded() Returns the key material of this secret key.
String getFormat() Returns the name of the encoding format for this secret key.
int hashCode() Calculates a hash code value for the object.