def decrypt(self, encrypted: str, private_key: RSAPrivateKeyWithSerialization) -> str: original_message = private_key.decrypt( binascii.a2b_base64(encrypted), padding.OAEP(mgf=padding.MGF1(algorithm=hashes.SHA256()), algorithm=hashes.SHA256(), label=None)) return original_message.decode("utf-8")
def decrypt(priv_key: rsa.RSAPrivateKeyWithSerialization, msg: bytes) -> bytes: """ Decrypts a message and returns the plain text. :param priv_key: RSA private key to decrypt the message with. :type priv_key: :class:`rsa.RSAPrivateKeyWithSerialization` :param msg: Message to decrypt :type msg: bytes :return: The decrypted message :rtype: :type:`str` """ return priv_key.decrypt(msg, padding.OAEP( mgf=padding.MGF1(algorithm=hashes.SHA256()), algorithm=hashes.SHA256(), label=None))