Class Argon2PasswordEncoder
- All Implemented Interfaces:
PasswordEncoder
Argon2 (RFC 9106) as a PasswordEncoder: argon2id, argon2i and argon2d,
stored in the PHC string format every framework writes.
| format | stored value |
|---|---|
Argon2PasswordEncoder.Format.PHC |
$argon2id$v=19$m=<KiB>,t=<passes>,p=<lanes>$<salt>$<hash> -- Spring Security, passlib, argon2-cffi |
Argon2PasswordEncoder.Format.DJANGO |
argon2$argon2id$v=19$m=...,t=...,p=...$<salt>$<hash> |
PasswordEncoderFactories.createDelegatingPasswordEncoder() registers the
PHC layout as {argon2}, which reads what Spring's
Argon2PasswordEncoder stores. For a Django table, register the Django
layout under an id of its own:
encoders.put("django-argon2", new Argon2PasswordEncoder(Argon2PasswordEncoder.Format.DJANGO));
A stored value names its own cost. One asking for more than maxMemory
KiB (128 MiB by default), more than maxIterations passes (64) or more than
maxParallelism lanes (64) does not verify, so a hostile row cannot take
the server's heap or a host thread for minutes.
Argon2 is computed in Java here, one lane after another; the lane count changes the result, as it must, but not the threading. A login occupies its host thread for the whole computation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe stored layouts read and written. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionThe PHC layout with Spring Security 5.8's defaults for a new hash (argon2id, 16 byte salt, 32 byte hash,p = 1,m = 16384,t = 2).Argon2PasswordEncoder(int saltLength, int hashLength, int parallelism, int memory, int iterations) Spring's constructor: the cost a new argon2id hash is written with, memory in KiB.format, writing new hashes with that framework's defaults.Argon2PasswordEncoder(Argon2PasswordEncoder.Format format, int saltLength, int hashLength, int parallelism, int memory, int iterations) formatwith the cost a new argon2id hash is written with, memory in KiB. -
Method Summary
Modifier and TypeMethodDescriptionstatic Argon2PasswordEncoderSpring's defaults as of Spring Security 5.8.encode(CharSequence rawPassword) The password as it should be stored: salted and hashed, so encoding one password twice gives two different results.booleanisReadable(String encodedPassword) WhetherencodedPasswordis a value of this layout within the memory, pass and lane limits.booleanmatches(CharSequence rawPassword, String encodedPassword) WhetherrawPasswordis the passwordencodedPasswordwas made from.voidsetMaxIterations(int maxIterations) The most passes a stored value may ask for.voidsetMaxMemory(long maxMemoryKib) The most memory, in KiB, a stored value may ask for.voidsetMaxParallelism(int maxParallelism) The most lanes a stored value may ask for.booleanupgradeEncoding(String encodedPassword) True when the stored value is not argon2id or was written with less memory or fewer passes than this encoder writes; always true for the Django layout, a format to migrate away from.
-
Field Details
-
ARGON2_D
public static final int ARGON2_Dargon2d: data-dependent memory access.- See Also:
-
ARGON2_I
public static final int ARGON2_Iargon2i: data-independent memory access.- See Also:
-
ARGON2_ID
public static final int ARGON2_IDargon2id: the hybrid RFC 9106 recommends.- See Also:
-
-
Constructor Details
-
Argon2PasswordEncoder
public Argon2PasswordEncoder()The PHC layout with Spring Security 5.8's defaults for a new hash (argon2id, 16 byte salt, 32 byte hash,p = 1,m = 16384,t = 2). -
Argon2PasswordEncoder
format, writing new hashes with that framework's defaults. -
Argon2PasswordEncoder
public Argon2PasswordEncoder(int saltLength, int hashLength, int parallelism, int memory, int iterations) Spring's constructor: the cost a new argon2id hash is written with, memory in KiB. -
Argon2PasswordEncoder
public Argon2PasswordEncoder(Argon2PasswordEncoder.Format format, int saltLength, int hashLength, int parallelism, int memory, int iterations) formatwith the cost a new argon2id hash is written with, memory in KiB.
-
-
Method Details
-
defaultsForSpringSecurity_v5_8
Spring's defaults as of Spring Security 5.8. -
setMaxMemory
public void setMaxMemory(long maxMemoryKib) The most memory, in KiB, a stored value may ask for. Default 131072. -
setMaxIterations
public void setMaxIterations(int maxIterations) The most passes a stored value may ask for. Default 64. -
setMaxParallelism
public void setMaxParallelism(int maxParallelism) The most lanes a stored value may ask for. Default 64. -
encode
Description copied from interface:PasswordEncoderThe password as it should be stored: salted and hashed, so encoding one password twice gives two different results.- Specified by:
encodein interfacePasswordEncoder
-
matches
Description copied from interface:PasswordEncoderWhetherrawPasswordis the passwordencodedPasswordwas made from.- Specified by:
matchesin interfacePasswordEncoder
-
upgradeEncoding
True when the stored value is not argon2id or was written with less memory or fewer passes than this encoder writes; always true for the Django layout, a format to migrate away from.- Specified by:
upgradeEncodingin interfacePasswordEncoder
-
isReadable
WhetherencodedPasswordis a value of this layout within the memory, pass and lane limits. What a migration asks before importing a row.
-