Enum ScramMechanism

java.lang.Object
java.lang.Enum<ScramMechanism>
com.ongres.scram.common.ScramMechanism
All Implemented Interfaces:
Serializable, Comparable<ScramMechanism>

public enum ScramMechanism extends Enum<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 Details

    • SCRAM_SHA_1

      public static final ScramMechanism SCRAM_SHA_1
      SCRAM-SHA-1 mechanism, defined in RFC-5802.
    • SCRAM_SHA_1_PLUS

      public static final ScramMechanism SCRAM_SHA_1_PLUS
      SCRAM-SHA-1-PLUS mechanism, defined in RFC-5802.
    • SCRAM_SHA_224

      public static final ScramMechanism SCRAM_SHA_224
      SCRAM-SHA-224 mechanism, not defined in an RFC.
    • SCRAM_SHA_224_PLUS

      public static final ScramMechanism SCRAM_SHA_224_PLUS
      SCRAM-SHA-224-PLUS mechanism, not defined in an RFC.
    • SCRAM_SHA_256

      public static final ScramMechanism SCRAM_SHA_256
      SCRAM-SHA-256 mechanism, defined in RFC-7677.
    • SCRAM_SHA_256_PLUS

      public static final ScramMechanism SCRAM_SHA_256_PLUS
      SCRAM-SHA-256-PLUS mechanism, defined in RFC-7677.
    • SCRAM_SHA_384

      public static final ScramMechanism SCRAM_SHA_384
      SCRAM-SHA-384 mechanism, not defined in an RFC.
    • SCRAM_SHA_384_PLUS

      public static final ScramMechanism SCRAM_SHA_384_PLUS
      SCRAM-SHA-384-PLUS mechanism, not defined in an RFC.
    • SCRAM_SHA_512

      public static final ScramMechanism SCRAM_SHA_512
      SCRAM-SHA-512 mechanism.
    • SCRAM_SHA_512_PLUS

      public static final ScramMechanism SCRAM_SHA_512_PLUS
      SCRAM-SHA-512-PLUS mechanism.
  • Field Details

    • BY_NAME_MAPPING

      private static final @Unmodifiable Map<String,ScramMechanism> BY_NAME_MAPPING
    • SUPPORTED_MECHANISMS

      private static final @Unmodifiable List<String> SUPPORTED_MECHANISMS
    • mechanismName

      @NotNull private final @NotNull String mechanismName
    • hashAlgorithmName

      @NotNull private final @NotNull String hashAlgorithmName
    • keyLength

      private final int keyLength
    • hmacAlgorithmName

      @NotNull private final @NotNull String hmacAlgorithmName
    • keyFactoryAlgorithmName

      @NotNull private final @NotNull String keyFactoryAlgorithmName
    • channelBinding

      private final boolean channelBinding
    • iterationCount

      private final int iterationCount
  • Constructor Details

    • ScramMechanism

      private ScramMechanism(String name, String hashAlgorithmName, int keyLength, String hmacAlgorithmName, int iterationCount)
  • Method Details

    • values

      public static ScramMechanism[] 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

      public static ScramMechanism valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • getHashAlgorithmName

      @NotNull @NotNull 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:
      The name of the hash algorithm
    • getHmacAlgorithmName

      @NotNull @NotNull 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:
      The name of the HMAC algorithm
    • getName

      @NotNull public @NotNull String 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 key
      message - 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 string
      password - Password used
      salt - Salt used
      iterationCount - Number of iterations
      Returns:
      The salted password
      Throws:
      ScramRuntimeException - If the algorithm is not provided by current JVM or any included implementations
    • byName

      @Nullable public static @Nullable ScramMechanism byName(@NotNull @NotNull String name)
      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

      @NotNull public static @Unmodifiable @NotNull List<@NotNull String> supportedMechanisms()
      List all the supported SCRAM mechanisms by this client implementation.
      Returns:
      A unmodifiable list of the IANA-registered, SCRAM supported mechanisms
    • isAlgorithmSupported

      private static boolean isAlgorithmSupported(@NotNull @NotNull ScramMechanism mechanism)