Class ModularCrypt

java.lang.Object
org.wildfly.security.password.util.ModularCrypt

public final class ModularCrypt extends Object
Helper utility methods for operation on passwords based on the Modular Crypt Format(MCF).
Author:
Juraci Paixão Kröhling, David M. Lloyd
  • Method Details

    • identifyAlgorithm

      public static String identifyAlgorithm(char[] chars)
      Attempt to identify the algorithm used by the given crypt string password.
      Parameters:
      chars - the password crypt string characters
      Returns:
      the algorithm name, or null if no algorithm could be guessed
    • encode

      public static char[] encode(Password password) throws InvalidKeySpecException
      Encode the given Password to a char array.
      Parameters:
      password - the password to encode
      Returns:
      a char array representing the encoded password
      Throws:
      InvalidKeySpecException - if the given password is not supported or could be encoded
    • encodeAsString

      public static String encodeAsString(Password password) throws InvalidKeySpecException
      Encode the given Password to a string.
      Parameters:
      password - the password to encode
      Returns:
      a string representing the encoded password
      Throws:
      InvalidKeySpecException - if the given password is not supported or could be encoded
    • decode

      public static Password decode(String cryptString) throws InvalidKeySpecException
      Decode the given string and creates a Password instance.
      Parameters:
      cryptString - the string representing the encoded format of the password
      Returns:
      a Password instance created from the given string
      Throws:
      InvalidKeySpecException - if the given password is not supported or could be decoded
    • decode

      public static Password decode(char[] cryptString) throws InvalidKeySpecException
      Decode the given char array and creates a Password instance.
      Parameters:
      cryptString - the char array representing the encoded format of the password
      Returns:
      a Password instance created from the given string
      Throws:
      InvalidKeySpecException - if the given password is not supported or could be decoded
    • createPassword

      public static Password createPassword(byte[] password, String algorithm) throws InvalidKeySpecException
      Throws:
      InvalidKeySpecException
    • composePassword

      public static void composePassword(ByteArrayOutputStream out, Password password) throws IOException
      Throws:
      IOException