Package com.ongres.scram.common
Enum Class ScramMechanisms
- All Implemented Interfaces:
ScramMechanism
,Serializable
,Comparable<ScramMechanisms>
,Constable
SCRAM Mechanisms supported by this library.
At least, SCRAM-SHA-1 and SCRAM-SHA-256 are provided, since both the hash and the HMAC implementations
are provided by the Java JDK version 6 or greater.
MessageDigest
: "Every implementation of the Java platform is required to support the
following standard MessageDigest algorithms: MD5, SHA-1, SHA-256".
Mac
: "Every implementation of the Java platform is required to support the following
standard Mac algorithms: HmacMD5, HmacSHA1, HmacSHA256".- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum Constants -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
ScramMechanisms
(String name, String hashAlgorithmName, int keyLength, String hmacAlgorithmName, boolean channelBinding, int priority) -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the length of the key length of the algorithm.static ScramMechanisms
Gets a SCRAM mechanism, given its standard IANA name.byte[]
digest
(byte[] message) Calculate a message digest, according to the algorithm of the SCRAM mechanism.protected String
Method that returns the name of the hash algorithm.protected String
Method that returns the name of the HMAC algorithm.getName()
The name of the mechanism, which must be a value registered under IANA: SASL SCRAM Family Mechanismsbyte[]
hmac
(byte[] key, byte[] message) Calculate the hmac of a key and a message, according to the algorithm of the SCRAM mechanism.byte[]
saltedPassword
(StringPreparation stringPreparation, String password, byte[] salt, int iterations) Compute the salted passwordstatic ScramMechanism
selectMatchingMechanism
(boolean channelBinding, String... peerMechanisms) This class classifies SCRAM mechanisms by two properties: whether they support channel binding; and a priority, which is higher for safer algorithms (like SHA-256 vs SHA-1).boolean
Whether this mechanism supports channel bindingstatic ScramMechanisms
Returns the enum constant of this class with the specified name.static ScramMechanisms[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.private static Map<String,
ScramMechanisms>
-
Enum Constant Details
-
SCRAM_SHA_1
-
SCRAM_SHA_1_PLUS
-
SCRAM_SHA_256
-
SCRAM_SHA_256_PLUS
-
-
Field Details
-
SCRAM_MECHANISM_NAME_PREFIX
- See Also:
-
CHANNEL_BINDING_SUFFIX
- See Also:
-
PBKDF2_PREFIX_ALGORITHM_NAME
- See Also:
-
BY_NAME_MAPPING
-
mechanismName
-
hashAlgorithmName
-
keyLength
private final int keyLength -
hmacAlgorithmName
-
channelBinding
private final boolean channelBinding -
priority
private final int priority
-
-
Constructor Details
-
ScramMechanisms
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
getHashAlgorithmName
Method that returns the name of the hash algorithm. It is protected since should be of no interest for direct users. The instance is supposed to provide abstractions over the algorithm names, and are not meant to be directly exposed.- Returns:
- The name of the hash algorithm
-
getHmacAlgorithmName
Method that returns the name of the HMAC algorithm. It is protected since should be of no interest for direct users. The instance is supposed to provide abstractions over the algorithm names, and are not meant to be directly exposed.- Returns:
- The name of the HMAC algorithm
-
getName
Description copied from interface:ScramMechanism
The name of the mechanism, which must be a value registered under IANA: SASL SCRAM Family Mechanisms- Specified by:
getName
in interfaceScramMechanism
- Returns:
- The mechanism name
-
supportsChannelBinding
public boolean supportsChannelBinding()Description copied from interface:ScramMechanism
Whether this mechanism supports channel binding- Specified by:
supportsChannelBinding
in interfaceScramMechanism
- Returns:
- True if it supports channel binding, false otherwise
-
algorithmKeyLength
public int algorithmKeyLength()Description copied from interface:ScramMechanism
Returns the length of the key length of the algorithm.- Specified by:
algorithmKeyLength
in interfaceScramMechanism
- Returns:
- The length (in bits)
-
digest
public byte[] digest(byte[] message) Description copied from interface:ScramMechanism
Calculate a message digest, according to the algorithm of the SCRAM mechanism.- Specified by:
digest
in interfaceScramMechanism
- Parameters:
message
- the message- Returns:
- The calculated message digest
-
hmac
public byte[] hmac(byte[] key, byte[] message) Description copied from interface:ScramMechanism
Calculate the hmac of a key and a message, according to the algorithm of the SCRAM mechanism.- Specified by:
hmac
in interfaceScramMechanism
- Parameters:
key
- the keymessage
- the message- Returns:
- The calculated message hmac instance
-
saltedPassword
public byte[] saltedPassword(StringPreparation stringPreparation, String password, byte[] salt, int iterations) Description copied from interface:ScramMechanism
Compute the salted password- Specified by:
saltedPassword
in interfaceScramMechanism
- Returns:
- The salted password
-
byName
Gets a SCRAM mechanism, given its standard IANA name.- Parameters:
name
- The standard IANA full name of the mechanism.- Returns:
- An Optional instance that contains the ScramMechanism if it was found, or empty otherwise.
-
selectMatchingMechanism
public static ScramMechanism selectMatchingMechanism(boolean channelBinding, String... peerMechanisms) This class classifies SCRAM mechanisms by two properties: whether they support channel binding; and a priority, which is higher for safer algorithms (like SHA-256 vs SHA-1). Given a list of SCRAM mechanisms supported by the peer, pick one that matches the channel binding requirements and has the highest priority.- Parameters:
channelBinding
- The type of matching mechanism searched forpeerMechanisms
- The mechanisms supported by the other peer- Returns:
- The selected mechanism, or null if no mechanism matched
-
valuesAsMap
-