MySQLPacketHandshakeResponse41.createWithCachingSha2Password constructor

MySQLPacketHandshakeResponse41.createWithCachingSha2Password({
  1. required String username,
  2. required String password,
  3. required MySQLPacketInitialHandshake initialHandshakePayload,
})

Implementation

factory MySQLPacketHandshakeResponse41.createWithCachingSha2Password({
  required String username,
  required String password,
  required MySQLPacketInitialHandshake initialHandshakePayload,
}) {
  final challenge = initialHandshakePayload.authPluginDataPart1 +
      initialHandshakePayload.authPluginDataPart2!.sublist(0, 12);

  assert(challenge.length == 20);

  final passwordBytes = utf8.encode(password);

  final authData = xor(
    sha256(passwordBytes),
    sha256(sha256(sha256(passwordBytes)) + challenge),
  );

  return MySQLPacketHandshakeResponse41(
    capabilityFlags: _supportedCapabitilies,
    maxPacketSize: 50 * 1024 * 1024,
    authPluginName: initialHandshakePayload.authPluginName!,
    characterSet: initialHandshakePayload.charset,
    authResponse: authData,
    username: username,
  );
}