Encrypt a message and send it

Encrypt a message and send it.

def send_msg(private_key_file, msg, send_msg_from, send_msg_to, send_msg_id):
    privkey_bytes = read_privkey_file(private_key_file)
    privkey = keys.UmbralPrivateKey.from_bytes(privkey_bytes)
    pubkey = privkey.get_pubkey()

    plaintext = msg.encode()
    ciphertext, capsule = pre.encrypt(pubkey, plaintext)

    data = '{"from":"' + send_msg_from + '", "to":"' + send_msg_to + '", "msg_id":"' + send_msg_id + '", "ciphertext": "' + ciphertext.hex() + '", "capsule": "' + capsule.to_bytes().hex() + '"}'
    subprocess.call(['cleos', 'push', 'action', DEFAULT_ACCOUNT, 'sendmsg', data , '-p', send_msg_from])
Close Menu
×

Cart