Class SecretChars
java.lang.Object
co.ankatech.ankasecure.sdk.security.SecretChars
- All Implemented Interfaces:
AutoCloseable
Owning wrapper for a sensitive
char[] (typically passwords, passphrases, or other
character-secret material returned by System.console().readPassword() or by JCA
APIs that operate on char[]).
Zeroizes on close() via Zeroization.zeroize(char[]) (space-fill ' '),
then nulls the internal field reference. Use only inside try-with-resources blocks.
The contract takes ownership of the supplied array — the caller must NOT retain a
reference to it. Access after close() throws IllegalStateException.
close() is idempotent.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
SecretChars
public SecretChars(char[] owned) Takes ownership of the supplied array.- Throws:
NullPointerException- ifownedisnull
-
-
Method Details
-
chars
public char[] chars()- Returns:
- the underlying char array
- Throws:
IllegalStateException- ifclose()has been called
-
length
public int length()- Returns:
- the length of the underlying buffer
- Throws:
IllegalStateException- ifclose()has been called
-
isClosed
public boolean isClosed()- Returns:
trueifclose()has been called; never throws
-
close
public void close()Zeroizes the underlyingchar[](space-fill' '), nulls the internal field, and marks this wrapper as closed. Idempotent.- Specified by:
closein interfaceAutoCloseable
-