SecureByteString

An immutable sequence of bytes containing sensitive data with memory clearing on disposal.

Instances of this class hold sensitive data in an internal buffer. When the data is no longer needed, callers should invoke destroy or close, or use Kotlin's use extension. Upon disposal, the internal memory 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 memory leaks if close is inadvertently omitted.

Parameters

data

the initial data. A defensive copy is stored.

Inheritors

Constructors

Link copied to clipboard
constructor(data: ByteArray)

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