<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def encrypt(payload, public_key):
 """ Encrypt a payload using an encrypted JSON wrapper. See: https://diaspora.github.io/diaspora_federation/federation/encryption.html :param payload: Payload document as a string. :param public_key: Public key of recipient as an RSA object. :return: Encrypted JSON wrapper as dict. """

        iv, key, encrypter = EncryptedPayload.get_iv_key_encrypter()
        aes_key_json = EncryptedPayload.get_aes_key_json(iv, key)
        cipher = PKCS1_v1_5.new(public_key)
        aes_key = b64encode(cipher.encrypt(aes_key_json))
        padded_payload = pkcs7_pad(payload.encode("utf-8"), AES.block_size)
        encrypted_me = b64encode(encrypter.encrypt(padded_payload))
        return {
            "aes_key": aes_key.decode("utf-8"),
            "encrypted_magic_envelope": encrypted_me.decode("utf8"),
        }