makeCachingSha2Password function
Hash password using MySQL 8+ method (SHA256) XOR(SHA256(password), SHA256(SHA256(SHA256(password)), scramble))
Implementation
List<int> makeCachingSha2Password(List<int>? scrambler, String? password) {
if (password == null) return [];
// SHA256(password)
final List<int> shaPwd = sha256.convert(utf8.encode(password)).bytes;
// SHA256(SHA256(password))
final List<int> shaShaPwd = sha256.convert(shaPwd).bytes;
// SHA256(SHA256(SHA256(password)), scramble)
final List<int> res = sha256.convert(List.from(shaShaPwd)..addAll(scrambler!)).bytes;
// XOR(SHA256(password), SHA256(SHA256(SHA256(password)), scramble))
for (int i = 0; i < res.length; i++) res[i] ^= shaPwd[i];
return res;
}