MCPcopy Create free account
hub / github.com/PyMySQL/PyMySQL / sha2_rsa_encrypt

Function sha2_rsa_encrypt

pymysql/_auth.py:136–155  ·  view source on GitHub ↗

Encrypt password with salt and public_key. Used for sha256_password and caching_sha2_password.

(password, salt, public_key)

Source from the content-addressed store, hash-verified

134
135
136def sha2_rsa_encrypt(password, salt, public_key):
137 """Encrypt password with salt and public_key.
138
139 Used for sha256_password and caching_sha2_password.
140 """
141 if not _have_cryptography:
142 raise RuntimeError(
143 "'cryptography' package is required for sha256_password or"
144 + " caching_sha2_password auth methods"
145 )
146 message = _xor_password(password + b"\0", salt)
147 rsa_key = serialization.load_pem_public_key(public_key, default_backend())
148 return rsa_key.encrypt(
149 message,
150 padding.OAEP(
151 mgf=padding.MGF1(algorithm=hashes.SHA1()),
152 algorithm=hashes.SHA1(),
153 label=None,
154 ),
155 )
156
157
158def sha256_password_auth(conn, pkt):

Callers 2

sha256_password_authFunction · 0.85

Calls 1

_xor_passwordFunction · 0.85

Tested by

no test coverage detected