Package com.ongres.scram.common
Enum ScramMechanism
- All Implemented Interfaces:
Serializable
,Comparable<ScramMechanism>
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 8 or greater.
MessageDigest
: "Every implementation of the Java platform is required to
support the following standard MessageDigest algorithms: SHA-1
, SHA-256
".
Mac
: "Every implementation of the Java platform is required to support
the following standard Mac algorithms: HmacSHA1
, HmacSHA256
".
- See Also:
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionSCRAM-SHA-1 mechanism, defined in RFC-5802.SCRAM-SHA-1-PLUS mechanism, defined in RFC-5802.SCRAM-SHA-224 mechanism, not defined in an RFC.SCRAM-SHA-224-PLUS mechanism, not defined in an RFC.SCRAM-SHA-256 mechanism, defined in RFC-7677.SCRAM-SHA-256-PLUS mechanism, defined in RFC-7677.SCRAM-SHA-384 mechanism, not defined in an RFC.SCRAM-SHA-384-PLUS mechanism, not defined in an RFC.SCRAM-SHA-512 mechanism.SCRAM-SHA-512-PLUS mechanism. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
ScramMechanism
(String name, String hashAlgorithmName, int keyLength, String hmacAlgorithmName, int iterationCount) -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable ScramMechanism
Gets a SCRAM mechanism given its standard IANA name, supported by the Java security provider.(package private) byte @NotNull []
digest
(byte @NotNull [] message) Calculate a message digest, according to the algorithm of the SCRAM mechanism.(package private) @NotNull String
Method that returns the name of the hash algorithm.(package private) @NotNull String
Method that returns the name of the HMAC algorithm.(package private) int
(package private) int
Returns the length of the key length of the algorithm.@NotNull String
getName()
The name of the mechanism.(package private) byte @NotNull []
hmac
(byte @NotNull [] key, byte @NotNull [] message) Calculate the hmac of a key and a message, according to the algorithm of the SCRAM mechanism.private static boolean
isAlgorithmSupported
(@NotNull ScramMechanism mechanism) boolean
isPlus()
The mechanism-PLUS
require channel binding.(package private) byte @NotNull []
saltedPassword
(@NotNull StringPreparation stringPreparation, char @NotNull [] password, byte @NotNull [] salt, int iterationCount) Compute the salted password.List all the supported SCRAM mechanisms by this client implementation.static ScramMechanism
Returns the enum constant of this type with the specified name.static ScramMechanism[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
SCRAM_SHA_1
SCRAM-SHA-1 mechanism, defined in RFC-5802. -
SCRAM_SHA_1_PLUS
SCRAM-SHA-1-PLUS mechanism, defined in RFC-5802. -
SCRAM_SHA_224
SCRAM-SHA-224 mechanism, not defined in an RFC. -
SCRAM_SHA_224_PLUS
SCRAM-SHA-224-PLUS mechanism, not defined in an RFC. -
SCRAM_SHA_256
SCRAM-SHA-256 mechanism, defined in RFC-7677. -
SCRAM_SHA_256_PLUS
SCRAM-SHA-256-PLUS mechanism, defined in RFC-7677. -
SCRAM_SHA_384
SCRAM-SHA-384 mechanism, not defined in an RFC. -
SCRAM_SHA_384_PLUS
SCRAM-SHA-384-PLUS mechanism, not defined in an RFC. -
SCRAM_SHA_512
SCRAM-SHA-512 mechanism. -
SCRAM_SHA_512_PLUS
SCRAM-SHA-512-PLUS mechanism.
-
-
Field Details
-
BY_NAME_MAPPING
-
SUPPORTED_MECHANISMS
-
mechanismName
-
hashAlgorithmName
-
keyLength
private final int keyLength -
hmacAlgorithmName
-
keyFactoryAlgorithmName
-
channelBinding
private final boolean channelBinding -
iterationCount
private final int iterationCount
-
-
Constructor Details
-
ScramMechanism
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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 type 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
The name of the mechanism.Must be a value registered under IANA: SASL SCRAM Family Mechanisms
- Returns:
- The mechanism name
-
isPlus
public boolean isPlus()The mechanism-PLUS
require channel binding.- Returns:
- true if the mechanism requires channel binding
-
getKeyLength
int getKeyLength()Returns the length of the key length of the algorithm.- Returns:
- The length (in bits)
-
getIterationCount
int getIterationCount() -
digest
byte @NotNull [] digest(byte @NotNull [] message) Calculate a message digest, according to the algorithm of the SCRAM mechanism.- Parameters:
message
- the message- Returns:
- The calculated message digest
- Throws:
ScramRuntimeException
- If the algorithm is not provided by current JVM or any included implementations
-
hmac
byte @NotNull [] hmac(byte @NotNull [] key, byte @NotNull [] message) Calculate the hmac of a key and a message, according to the algorithm of the SCRAM mechanism.- Parameters:
key
- the keymessage
- the message- Returns:
- The calculated message hmac instance
- Throws:
ScramRuntimeException
- If the algorithm is not provided by current JVM or any included implementations
-
saltedPassword
byte @NotNull [] saltedPassword(@NotNull @NotNull StringPreparation stringPreparation, char @NotNull [] password, byte @NotNull [] salt, int iterationCount) Compute the salted password.- Parameters:
stringPreparation
- Type of preparation to perform in the stringpassword
- Password usedsalt
- Salt usediterationCount
- Number of iterations- Returns:
- The salted password
- Throws:
ScramRuntimeException
- If the algorithm is not provided by current JVM or any included implementations
-
byName
Gets a SCRAM mechanism given its standard IANA name, supported by the Java security provider.- Parameters:
name
- The standard IANA full name of the mechanism.- Returns:
- An instance that contains the ScramMechanism if it was found, or null otherwise.
-
supportedMechanisms
List all the supported SCRAM mechanisms by this client implementation.- Returns:
- A unmodifiable list of the IANA-registered, SCRAM supported mechanisms
-
isAlgorithmSupported
-