public interface Password extends Destroyable
PasswordManager, that exist in
several flavors. To pick one, use the PasswordManagerFactory or
supply your own implementation (your own implementation can be set as the
default one with the discovery service).
// pick one of the available password manager // (replace XXX with the one you prefer) PasswordManager manager = PasswordManagerFactory.getXXXPasswordManager(); Password pwd = manager.newPassword(pwdChars); // from this point, // pwd is safe for staying in memory as long as necessary, // pwdChars has been unset after the creation of the password.
try (Password.Clear clear = pwd.getClearCopy()) {
char[] clearPwd = clear.get();
// use clearPwd in the block
}
// at this point clearPwd has been unset
// before being eligible by the garbage collector
ml.alternet.security,
Password.Clear,
PasswordManager,
PasswordManagerFactory,
DiscoveryService| Modifier and Type | Interface and Description |
|---|---|
static interface |
Password.Clear
This class helps keeping low the period where a password appear in clear
in the memory, in order to make it difficult to find when a memory dump
is performed.
|
| Modifier and Type | Method and Description |
|---|---|
void |
destroy()
Invalidate this password.
|
Password.Clear |
getClearCopy()
Wrap this password in a clear copy.
|
default boolean |
isDestroyed() |
static Password |
newPassword(char[] password)
Obfuscate the given password in a new Password instance.
|
PasswordState |
state()
Return the state of this password.
|
static Password newPassword(char[] password)
password - The password to obfuscate ; may be null or empty ; that char
array is cleared when returningEmptyPassword.SINGLETON,
PasswordManagerFactory.getDefaultPasswordManager()default boolean isDestroyed()
isDestroyed in interface Destroyablevoid destroy()
destroy in interface DestroyablePasswordState state()
Empty, Valid, or InvalidPassword.Clear getClearCopy() throws IllegalStateException
IllegalStateException - If this password has been invalidated.Copyright © 2018 Alternet. All rights reserved.