Class Security

java.lang.Object
com.mysql.jdbc.Security

public class Security extends Object
Methods for doing secure authentication with MySQL-4.1 and newer.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static byte[]
    Creates key from old password to decode scramble Used in 4.1 authentication with passwords stored pre-4.1 hashing.
    (package private) static byte[]
    getBinaryPassword(int[] salt, boolean usingNewPasswords)
     
    (package private) static String
    Creates password to be stored in user database from raw string.
    (package private) static byte[]
    Stage one password hashing, used in MySQL 4.1 password handling
    (package private) static byte[]
    passwordHashStage2(byte[] hashedPassword, byte[] salt)
    Stage two password hashing used in MySQL 4.1 password handling
    static byte[]
    scramble411(String password, String seed, String passwordEncoding)
     
    static byte[]
    scrambleCachingSha2(byte[] password, byte[] seed)
    Scrambling for caching_sha2_password plugin.
    static void
    xorString(byte[] from, byte[] to, byte[] scramble, int length)
    Encrypt/Decrypt function used for password encryption in authentication Simple XOR is used here but it is OK as we encrypt random strings

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • createKeyFromOldPassword

      static byte[] createKeyFromOldPassword(String passwd) throws NoSuchAlgorithmException
      Creates key from old password to decode scramble Used in 4.1 authentication with passwords stored pre-4.1 hashing.
      Parameters:
      passwd - the password to create the key from
      Returns:
      20 byte generated key
      Throws:
      NoSuchAlgorithmException - if the message digest 'SHA-1' is not available.
    • getBinaryPassword

      static byte[] getBinaryPassword(int[] salt, boolean usingNewPasswords) throws NoSuchAlgorithmException
      Parameters:
      salt -
      usingNewPasswords -
      Throws:
      NoSuchAlgorithmException - if the message digest 'SHA-1' is not available.
    • makeScrambledPassword

      static String makeScrambledPassword(String password) throws NoSuchAlgorithmException
      Creates password to be stored in user database from raw string. Handles Pre-MySQL 4.1 passwords.
      Parameters:
      password - plaintext password
      Returns:
      scrambled password
      Throws:
      NoSuchAlgorithmException - if the message digest 'SHA-1' is not available.
    • xorString

      public static void xorString(byte[] from, byte[] to, byte[] scramble, int length)
      Encrypt/Decrypt function used for password encryption in authentication Simple XOR is used here but it is OK as we encrypt random strings
      Parameters:
      from - IN Data for encryption
      to - OUT Encrypt data to the buffer (may be the same)
      scramble - IN Scramble used for encryption
      length - IN Length of data to encrypt
    • passwordHashStage1

      static byte[] passwordHashStage1(String password) throws NoSuchAlgorithmException
      Stage one password hashing, used in MySQL 4.1 password handling
      Parameters:
      password - plaintext password
      Returns:
      stage one hash of password
      Throws:
      NoSuchAlgorithmException - if the message digest 'SHA-1' is not available.
    • passwordHashStage2

      static byte[] passwordHashStage2(byte[] hashedPassword, byte[] salt) throws NoSuchAlgorithmException
      Stage two password hashing used in MySQL 4.1 password handling
      Parameters:
      salt - salt used for stage two hashing
      hash - from passwordHashStage1
      Returns:
      result of stage two password hash
      Throws:
      NoSuchAlgorithmException - if the message digest 'SHA-1' is not available.
    • scramble411

      public static byte[] scramble411(String password, String seed, String passwordEncoding) throws NoSuchAlgorithmException, UnsupportedEncodingException
      Throws:
      NoSuchAlgorithmException
      UnsupportedEncodingException
    • scrambleCachingSha2

      public static byte[] scrambleCachingSha2(byte[] password, byte[] seed) throws DigestException
      Scrambling for caching_sha2_password plugin.
      Scramble = XOR(SHA2(password), SHA2(SHA2(SHA2(password)), Nonce))
      
      Throws:
      DigestException