Top Description Fields Constructors Methods
com.mysql.cj.protocol

public Class Security

extends Object
Class Inheritance
Imports
java.security.DigestException, .MessageDigest, .NoSuchAlgorithmException, com.mysql.cj.exceptions.AssertionFailedException, com.mysql.cj.util.StringUtils

Methods for doing secure authentication with MySQL-4.1 and newer.

Field Summary

Modifier and TypeField and Description
private static int

Constructor Summary

AccessConstructor and Description
private
Security()

Prevent construction.

Method Summary

Modifier and TypeMethod and Description
public static byte[]
scramble411(String password, byte[] seed, String passwordEncoding)

public static byte[]

Returns:

bytes
scramble411
(byte[]
password
password
,
byte[]
seed
seed
)

Hashing for MySQL-4.1 authentication.

public static byte[]

Returns:

bytes
scrambleCachingSha2
(byte[]
password
password
,
byte[]
seed
seed
)

Scrambling for caching_sha2_password plugin.

public static void
xorString(byte[]
IN Data for encryption
from
,
byte[]
OUT Encrypt data to the buffer (may be the same)
to
,
byte[]
IN Scramble used for encryption
scramble
,
int
IN Length of data to encrypt
length
)

Encrypt/Decrypt function used for password encryption in authentication Simple XOR is used here but it is OK as we encrypt random strings

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CACHING_SHA2_DIGEST_LENGTHback to summary
private static int CACHING_SHA2_DIGEST_LENGTH

Constructor Detail

Securityback to summary
private Security()

Prevent construction.

Method Detail

scramble411back to summary
public static byte[] scramble411(String password, byte[] seed, String passwordEncoding)
scramble411back to summary
public static byte[] scramble411(byte[] password, byte[] seed)

Hashing for MySQL-4.1 authentication. Algorithm is as follows (c.f. sql/auth/password.c):

SERVER: public_seed=create_random_string()
send(public_seed)

CLIENT: recv(public_seed)
hash_stage1=sha1("password")
hash_stage2=sha1(hash_stage1)
reply=xor(hash_stage1, sha1(public_seed,hash_stage2))
send(reply)
Parameters
password:byte[]

password

seed:byte[]

seed

Returns:byte[]

bytes

scrambleCachingSha2back to summary
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))
Parameters
password:byte[]

password

seed:byte[]

seed

Returns:byte[]

bytes

Exceptions
DigestException:
if an error occurs
xorStringback to summary
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:byte[]

IN Data for encryption

to:byte[]

OUT Encrypt data to the buffer (may be the same)

scramble:byte[]

IN Scramble used for encryption

length:int

IN Length of data to encrypt