MySQLPacketAuthSwitchResponse.createWithCachingSha2Password constructor

MySQLPacketAuthSwitchResponse.createWithCachingSha2Password({
  1. required String password,
  2. required Uint8List challenge,
})

Cria uma resposta de autenticação para o plugin caching_sha2_password.

Implementation

factory MySQLPacketAuthSwitchResponse.createWithCachingSha2Password({
  required String password,
  required Uint8List challenge,
}) {
  assert(challenge.length == 20);
  if (password == '') {
    return MySQLPacketAuthSwitchResponse(authData: Uint8List(0));
  }

  final passwordBytes = utf8.encode(password);
  final authData = xor(
    sha256(passwordBytes),
    sha256([...sha256(sha256(passwordBytes)), ...challenge]),
  );

  return MySQLPacketAuthSwitchResponse(
    authData: authData,
  );
}