Top Description Fields Constructors Methods
com.ongres.scram.common

public final Enum ScramMechanisms

extends Enum<ScramMechanisms>
implements ScramMechanism
Class Inheritance
All Implemented Interfaces
com.ongres.scram.common.ScramMechanism
Static Imports
com.ongres.scram.common.util.Preconditions.checkNotNull, .Preconditions.gt0

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. java.security.MessageDigest: "Every implementation of the Java platform is required to support the following standard MessageDigest algorithms: MD5, SHA-1, SHA-256". javax.crypto.Mac: "Every implementation of the Java platform is required to support the following standard Mac algorithms: HmacMD5, HmacSHA1, HmacSHA256".
See Also
SASL SCRAM Family Mechanisms

Field Summary

Modifier and TypeField and Description
private static final Map<String, ScramMechanisms>
private static final String
private final boolean
private final String
private final String
private final int
private final String
private static final String
private final int
private static final String
public static final ScramMechanisms
public static final ScramMechanisms
public static final ScramMechanisms
public static final ScramMechanisms

Constructor Summary

AccessConstructor and Description
private
ScramMechanisms(String name, String hashAlgorithmName, int keyLength, String hmacAlgorithmName, boolean channelBinding, int priority)

Method Summary

Modifier and TypeMethod and Description
public int
algorithmKeyLength()

Implements com.ongres.scram.common.ScramMechanism.algorithmKeyLength.

Returns the length of the key length of the algorithm.
public static ScramMechanisms

Returns:

An Optional instance that contains the ScramMechanism if it was found, or empty otherwise.
byName
(String
The standard IANA full name of the mechanism.
name
)

Gets a SCRAM mechanism, given its standard IANA name.

public byte[]
digest(byte[]
the message
message
)

Implements com.ongres.scram.common.ScramMechanism.digest.

Calculate a message digest, according to the algorithm of the SCRAM mechanism.
protected String

Returns:

The name of the hash algorithm
getHashAlgorithmName
()

Method that returns the name of the hash algorithm.

protected String

Returns:

The name of the HMAC algorithm
getHmacAlgorithmName
()

Method that returns the name of the HMAC algorithm.

public String
getName()

Implements com.ongres.scram.common.ScramMechanism.getName.

The name of the mechanism, which must be a value registered under IANA: SASL SCRAM Family Mechanisms
public byte[]
hmac(byte[]
the key
key
,
byte[]
the message
message
)

Implements com.ongres.scram.common.ScramMechanism.hmac.

Calculate the hmac of a key and a message, according to the algorithm of the SCRAM mechanism.
public byte[]
saltedPassword(StringPreparation stringPreparation, String password, byte[] salt, int iterations)

Implements com.ongres.scram.common.ScramMechanism.saltedPassword.

Compute the salted password
public static ScramMechanism

Returns:

The selected mechanism, or null if no mechanism matched
selectMatchingMechanism
(boolean
The type of matching mechanism searched for
channelBinding
,
String...
The mechanisms supported by the other peer
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).

public boolean
supportsChannelBinding()

Implements com.ongres.scram.common.ScramMechanism.supportsChannelBinding.

Whether this mechanism supports channel binding
public static ScramMechanisms
public static ScramMechanisms[]
private static Map<String, ScramMechanisms>
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BY_NAME_MAPPINGback to summary
private static final Map<String, ScramMechanisms> BY_NAME_MAPPING
CHANNEL_BINDING_SUFFIXback to summary
private static final String CHANNEL_BINDING_SUFFIX
channelBindingback to summary
private final boolean channelBinding
hashAlgorithmNameback to summary
private final String hashAlgorithmName
hmacAlgorithmNameback to summary
private final String hmacAlgorithmName
keyLengthback to summary
private final int keyLength
mechanismNameback to summary
private final String mechanismName
PBKDF2_PREFIX_ALGORITHM_NAMEback to summary
private static final String PBKDF2_PREFIX_ALGORITHM_NAME
priorityback to summary
private final int priority
SCRAM_MECHANISM_NAME_PREFIXback to summary
private static final String SCRAM_MECHANISM_NAME_PREFIX
SCRAM_SHA_1back to summary
public static final ScramMechanisms SCRAM_SHA_1
SCRAM_SHA_1_PLUSback to summary
public static final ScramMechanisms SCRAM_SHA_1_PLUS
SCRAM_SHA_256back to summary
public static final ScramMechanisms SCRAM_SHA_256
SCRAM_SHA_256_PLUSback to summary
public static final ScramMechanisms SCRAM_SHA_256_PLUS

Constructor Detail

ScramMechanismsback to summary
private ScramMechanisms(String name, String hashAlgorithmName, int keyLength, String hmacAlgorithmName, boolean channelBinding, int priority)

Method Detail

algorithmKeyLengthback to summary
public int algorithmKeyLength()

Implements com.ongres.scram.common.ScramMechanism.algorithmKeyLength.

Doc from com.ongres.scram.common.ScramMechanism.algorithmKeyLength.

Returns the length of the key length of the algorithm.

Returns:int

The length (in bits)

Annotations
@Override
byNameback to summary
public static ScramMechanisms byName(String name)

Gets a SCRAM mechanism, given its standard IANA name.

Parameters
name:String

The standard IANA full name of the mechanism.

Returns:ScramMechanisms

An Optional instance that contains the ScramMechanism if it was found, or empty otherwise.

digestback to summary
public byte[] digest(byte[] message)

Implements com.ongres.scram.common.ScramMechanism.digest.

Doc from com.ongres.scram.common.ScramMechanism.digest.

Calculate a message digest, according to the algorithm of the SCRAM mechanism.

Parameters
message:byte[]

the message

Returns:byte[]

The calculated message digest

Annotations
@Override
getHashAlgorithmNameback to summary
protected String 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:String

The name of the hash algorithm

getHmacAlgorithmNameback to summary
protected String 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:String

The name of the HMAC algorithm

getNameback to summary
public String getName()

Implements com.ongres.scram.common.ScramMechanism.getName.

Doc from com.ongres.scram.common.ScramMechanism.getName.

The name of the mechanism, which must be a value registered under IANA: SASL SCRAM Family Mechanisms

Returns:String

The mechanism name

Annotations
@Override
hmacback to summary
public byte[] hmac(byte[] key, byte[] message)

Implements com.ongres.scram.common.ScramMechanism.hmac.

Doc from com.ongres.scram.common.ScramMechanism.hmac.

Calculate the hmac of a key and a message, according to the algorithm of the SCRAM mechanism.

Parameters
key:byte[]

the key

message:byte[]

the message

Returns:byte[]

The calculated message hmac instance

Annotations
@Override
saltedPasswordback to summary
public byte[] saltedPassword(StringPreparation stringPreparation, String password, byte[] salt, int iterations)

Implements com.ongres.scram.common.ScramMechanism.saltedPassword.

Doc from com.ongres.scram.common.ScramMechanism.saltedPassword.

Compute the salted password

Returns:byte[]

The salted password

Annotations
@Override
selectMatchingMechanismback to summary
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:boolean

The type of matching mechanism searched for

peerMechanisms:String[]

The mechanisms supported by the other peer

Returns:ScramMechanism

The selected mechanism, or null if no mechanism matched

supportsChannelBindingback to summary
public boolean supportsChannelBinding()

Implements com.ongres.scram.common.ScramMechanism.supportsChannelBinding.

Doc from com.ongres.scram.common.ScramMechanism.supportsChannelBinding.

Whether this mechanism supports channel binding

Returns:boolean

True if it supports channel binding, false otherwise

Annotations
@Override
valueOfback to summary
public static ScramMechanisms valueOf(String name)
valuesback to summary
public static ScramMechanisms[] values()
valuesAsMapback to summary
private static Map<String, ScramMechanisms> valuesAsMap()