Class SecretChars

java.lang.Object
co.ankatech.ankasecure.sdk.security.SecretChars
All Implemented Interfaces:
AutoCloseable

public final class SecretChars extends Object implements 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
    Constructor
    Description
    SecretChars(char[] owned)
    Takes ownership of the supplied array.
  • Method Summary

    Modifier and Type
    Method
    Description
    char[]
     
    void
    Zeroizes the underlying char[] (space-fill ' '), nulls the internal field, and marks this wrapper as closed.
    boolean
     
    int
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SecretChars

      public SecretChars(char[] owned)
      Takes ownership of the supplied array.
      Throws:
      NullPointerException - if owned is null
  • Method Details

    • chars

      public char[] chars()
      Returns:
      the underlying char array
      Throws:
      IllegalStateException - if close() has been called
    • length

      public int length()
      Returns:
      the length of the underlying buffer
      Throws:
      IllegalStateException - if close() has been called
    • isClosed

      public boolean isClosed()
      Returns:
      true if close() has been called; never throws
    • close

      public void close()
      Zeroizes the underlying char[] (space-fill ' '), nulls the internal field, and marks this wrapper as closed. Idempotent.
      Specified by:
      close in interface AutoCloseable