Package co.ankatech.ankasecure.sdk.security
package co.ankatech.ankasecure.sdk.security
The ANKASecure SDK secure-memory layer.
This package is the single sanctioned place in the SDK for handling sensitive
material on the client side: cryptographic keys, passwords, JWT bearer tokens, and any
byte[] or char[] that holds secrets after construction.
Public API
Zeroization— null-safe overwrite helpers forbyte[]andchar[], plus best-effortDestroyable.destroy()that swallowsDestroyFailedException.SecretBuffer—AutoCloseablewrapper for an ownedbyte[]. Zeroizes and nulls the field onSecretBuffer.close().SecretChars— same pattern forchar[]. Use for password / passphrase / sensitive char material.BearerToken— JWT holder backed bychar[]with a redactedtoString()(<first6>…[REDACTED]).
What this layer CAN guarantee
- Caller-owned
byte[]returned byCipher.doFinal(...),SecretKey.getEncoded(), etc., is overwritten with0x00when wrapped inSecretBufferand closed. - Caller-owned
char[]fromSystem.console().readPassword()is space-filled when wrapped inSecretCharsand closed. char[]insidePBEKeySpeccan be cleared viaclearPassword().- Passing a Bouncy Castle 1.86 ML-KEM, ML-DSA, SLH-DSA, FrodoKEM, Classic McEliece, XMSS,
XMSS^MT, LMS or HSS private key to
destroyIfPossible(Object)overwrites the key's secret arrays (at least one secret array reachable from the key is all-zero afterdestroy(); not a claim that every internal copy is cleared).
What this layer CANNOT guarantee
- Clearing every key object through
destroy(). An EC, SM2, RSA or GOST-2012 private key completesdestroy()and reports itself destroyed, but only drops its references: its secret is an immutableBigIntegerthat persists until collected. FALCON, HQC, BIKE, SABER, NTRU, NTRU LPRime, SMAUG-T, Ed25519, Ed448, X25519, X448,CompositePrivateKeyandSecretKeySpecthrowDestroyFailedException, whichdestroyIfPossibleswallows.MLKEMPrivateKeySpecandKeyParameterdo not implementDestroyableat all. - Bouncy Castle internal byte-array pools (released to the pool and reused without zeroization).
- JCA scratch buffers inside
Cipher.update / doFinal. - JIT register spills and stack-frame retention.
- OkHttp
okio.Buffersegment pool, JVM TLAB / young-gen retention, OS swap / hibernation files, native heap (BC PQC native implementations). Stringinterning and reachability — once secret material is wrapped in aString(e.g., vianew String(charArray)), it cannot be reliably erased. The SDK avoidsStringfor all sensitive material.
Build-time enforcement
Architecture rules fail the SDK build on:
Stringfields with names matchingpassword|secret|token|jwt|bearer| clientSecretoutside this package;SecretKey.getEncoded()invocations outside this package not consumed inside a try-with-resources ofSecretBuffer.
-
ClassesClassDescriptionHolder for a JWT bearer token represented as
char[]rather thanString, with a redactedBearerToken.toString()so accidental log statements do not leak the token verbatim.Mints the RFC 7523 §2.2 client assertion that proves an actor's identity with a registered key pair instead of a shared secret.Owning wrapper for a sensitivebyte[].Owning wrapper for a sensitivechar[](typically passwords, passphrases, or other character-secret material returned bySystem.console().readPassword()or by JCA APIs that operate onchar[]).Centralized zeroization helpers for the ANKASecure secure-memory layer.