| 122 | |
| 123 | |
| 124 | def _xor_password(password, salt): |
| 125 | # Trailing NUL character will be added in Auth Switch Request. |
| 126 | # See https://github.com/mysql/mysql-server/blob/7d10c82196c8e45554f27c00681474a9fb86d137/sql/auth/sha2_password.cc#L939-L945 |
| 127 | salt = salt[:SCRAMBLE_LENGTH] |
| 128 | password_bytes = bytearray(password) |
| 129 | # salt = bytearray(salt) # for PY2 compat. |
| 130 | salt_len = len(salt) |
| 131 | for i in range(len(password_bytes)): |
| 132 | password_bytes[i] ^= salt[i % salt_len] |
| 133 | return bytes(password_bytes) |
| 134 | |
| 135 | |
| 136 | def sha2_rsa_encrypt(password, salt, public_key): |