public final class SecretKey

  1. Object
  2. Key
  3. SecretKey

A symmetric secret key. Used with Cipher (AES) and Hmac (via raw bytes). For asymmetric algorithms use PublicKey / PrivateKey.

Keys carry the raw key material plus the algorithm name they are intended for. They do not enforce length or strength – that is the caller’s responsibility, although KeyGenerator will produce keys of standard lengths.

Constructors

public SecretKey(String algorithm, byte[] keyBytes)Wraps existing key material.

Methods

public int getBitLength()Returns the length of the key in bits.

Inherited methods

Constructor details

SecretKey

public SecretKey(String algorithm, byte[] keyBytes)
Wraps existing key material.

Parameters

algorithm String
algorithm identifier (e.g. “AES”)
keyBytes byte[]
raw key material – defensively copied

Method details

getBitLength

public int getBitLength()
Returns the length of the key in bits.