def encrypt_auth_ack_message(self, ack_message: bytes) -> bytes: if self.got_eip8_auth: # The EIP-8 version has an authenticated length prefix. prefix = struct.pack('>H', len(ack_message) + ENCRYPT_OVERHEAD_LENGTH) suffix = ecies.encrypt( ack_message, self.remote.pubkey, shared_mac_data=prefix) auth_ack = prefix + suffix else: auth_ack = ecies.encrypt(ack_message, self.remote.pubkey) return auth_ack
def test_encrypt_decrypt(): msg = b'test yeah' privkey = ecies.generate_privkey() ciphertext = ecies.encrypt(msg, privkey.public_key) decrypted = ecies.decrypt(ciphertext, privkey) assert decrypted == msg privkey2 = ecies.generate_privkey() with pytest.raises(ecies.DecryptionError): decrypted = ecies.decrypt(ciphertext, privkey2)
def encrypt_auth_message(self, auth_message: bytes) -> bytes: return ecies.encrypt(auth_message, self.remote.pubkey)