Class Security
java.lang.Object
com.mysql.jdbc.Security
Methods for doing secure authentication with MySQL-4.1 and newer.
-
Method Summary
Modifier and TypeMethodDescription(package private) static byte[]createKeyFromOldPassword(String passwd) 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 StringmakeScrambledPassword(String password) Creates password to be stored in user database from raw string.(package private) static byte[]passwordHashStage1(String password) 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 handlingstatic byte[]scramble411(String password, String seed, String passwordEncoding) static byte[]scrambleCachingSha2(byte[] password, byte[] seed) Scrambling for caching_sha2_password plugin.static voidxorString(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
-
Method Details
-
createKeyFromOldPassword
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
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 encryptionto- OUT Encrypt data to the buffer (may be the same)scramble- IN Scramble used for encryptionlength- IN Length of data to encrypt
-
passwordHashStage1
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 hashinghash- 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 -
scrambleCachingSha2
Scrambling for caching_sha2_password plugin.Scramble = XOR(SHA2(password), SHA2(SHA2(SHA2(password)), Nonce))
- Throws:
DigestException
-