SecretKey

class SecretKey(keyMaterial: ByteArray) : SecureByteString

A cryptographic secret key (symmetric key or shared secret) with memory clearing on disposal.

This is a specialized SecureByteString representing symmetric key material or shared secrets.

Instances of this class hold raw secret key material in an internal buffer. When the key is no longer needed, callers should invoke destroy or close, or use Kotlin's use extension. Upon disposal, the internal key material is overwritten with zeros using ByteArray.secureZero.

As a secondary safety net, an automatic cleaner (KeyDisposer) is registered at creation to zero the memory when the object becomes unreachable, guarding against leaks if close is inadvertently omitted.

Parameters

keyMaterial

the initial key material. A defensive copy is stored.

Constructors

Link copied to clipboard
constructor(keyMaterial: ByteArray)
constructor(byteString: SecureByteString)

Creates a secret key from an existing SecureByteString.

Properties

Link copied to clipboard

Returns a defensive copy of the underlying bytes.

Link copied to clipboard

Whether this byte string has been destroyed.

Link copied to clipboard
val size: Int

Size of the byte string in bytes.

Functions

Link copied to clipboard

Throws IllegalStateException if this byte string has been destroyed.

Link copied to clipboard
open override fun close()
Link copied to clipboard
fun destroy()

Wipes the data from memory and marks this byte string as destroyed.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
operator fun get(index: Int): Byte

Returns the byte at the specified index.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard

Returns true if this byte string is empty.

Link copied to clipboard

Returns true if this byte string is not empty.

Link copied to clipboard

Returns a defensive copy of the underlying bytes as a ByteArray.

Link copied to clipboard
Link copied to clipboard
open override fun toString(): String