@staticmethod<EOL><INDENT>def encrypt(payload, public_key):<DEDENT>
iv, key, encrypter = EncryptedPayload.get_iv_key_encrypter()<EOL>aes_key_json = EncryptedPayload.get_aes_key_json(iv, key)<EOL>cipher = PKCS1_v1_5.new(public_key)<EOL>aes_key = b64encode(cipher.encrypt(aes_key_json))<EOL>padded_payload = pkcs7_pad(payload.encode("<STR_LIT:utf-8>"), AES.block_size)<EOL>encrypted_me = b64encode(encrypter.encrypt(padded_payload))<EOL>return {<EOL>"<STR_LIT>": aes_key.decode("<STR_LIT:utf-8>"),<EOL>"<STR_LIT>": encrypted_me.decode("<STR_LIT:utf8>"),<EOL>}<EOL>
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.