Example #1
0
def decrypt_acrastruct(data, private_key, client_id=None, zone_id=None):
    public_key = data[8:8+45]
    encrypted_symmetric = data[8+45:8+45+84]
    smessage_decryptor = smessage.SMessage(private_key, public_key)
    symmetric = smessage_decryptor.unwrap(encrypted_symmetric)
    encrypted_data = data[8+45+84+8:]
    if zone_id:
        return scell.SCellSeal(symmetric).decrypt(encrypted_data, zone_id)
    else:
        return scell.SCellSeal(symmetric).decrypt(encrypted_data)
Example #2
0
 def __init__(self, private_key, peer_public_key=None, socket_=None):
     if socket_:
         self.socket = socket_
     else:
         self.socket = socket.socket()
     self.priv_key = private_key
     if peer_public_key:
         self.smessage = smessage.SMessage(private_key, peer_public_key)
     else:
         self.message = None
Example #3
0
    def encrypt_decrypt(self, private, public):
        with self.assertRaises(ThemisError):
            smessage.SMessage("", "")

        with self.assertRaises(ThemisError):
            smessage.SMessage(None, public)

        with self.assertRaises(ThemisError):
            smessage.SMessage(private, "")

        encryptor = smessage.SMessage(private, public)
        with self.assertRaises(ThemisError):
            encryptor.wrap("")

        encrypted_message = encryptor.wrap(self.message)
        with self.assertRaises(ThemisError):
            encryptor.unwrap(b"".join([encrypted_message, b"11"]))

        decrypted_message = encryptor.unwrap(encrypted_message)
        self.assertEqual(self.message, decrypted_message)
Example #4
0
 def set_peer_pub_key(self, peer_public_key):
     self.smessage = smessage.SMessage(self.priv_key, peer_public_key)
Example #5
0
        'Usage: <command: enc | dec | sign | verify > <send_private_key> <recipient_public_key> <message>'
    )
    exit(1)

command = sys.argv[COMMAND]
private_key_path = sys.argv[SENDER_PRIVATE_KEY]
public_key_path = sys.argv[RECIPIENT_PUBLIC_KEY]
message = sys.argv[MESSAGE]

with open(private_key_path, 'rb') as f:
    private_key = f.read()

with open(public_key_path, 'rb') as f:
    public_key = f.read()

message_encrypter = smessage.SMessage(private_key, public_key)

if command == 'enc':
    encrypted = message_encrypter.wrap(message.encode('utf-8'))
    encoded = b64encode(encrypted)
    print(encoded.decode('ascii'))
elif command == 'dec':
    decoded = b64decode(message.encode('utf-8'))
    decrypted = message_encrypter.unwrap(decoded)
    print(decrypted.decode('utf-8'))
elif command == 'sign':
    encrypted = smessage.ssign(private_key, message.encode('utf-8'))
    encoded = b64encode(encrypted)
    print(encoded.decode('ascii'))
elif command == 'verify':
    decoded = b64decode(message.encode('utf-8'))