Ejemplo n.º 1
0
    def decrypt_query(self, query: bytes):
        """
            Decrypts a query received by the server

            query - The query to decrypt
        """
        # Parse the server key

        # Parsre the msg, extract the pubkey and the {IV || payload} from the query
        pubkey = query[0:65]  # uncompressed pubkey's length is 65 bytes
        encrypted = query[65:]
        ephemeral_public_key = PublicKey(pubkey)

        # Generate the AES key
        aes_key = decapsulate(ephemeral_public_key, self.server_sk)
        return aes_decrypt(aes_key, encrypted), aes_key
Ejemplo n.º 2
0
def decrypt(receiver_prvhex: str, msg: bytes) -> bytes:
    """
    Decrypt with eth private key

    Parameters
    ----------
    receiver_pubhex: str
        Receiver's ethereum private key hex string
    msg: bytes
        Data to decrypt

    Returns
    -------
    bytes
        Plain text
    """
    pubkey = msg[0:65]  # pubkey's length is 65 bytes
    encrypted = msg[65:]
    sender_public_key = hex2pub(pubkey.hex())
    private_key = hex2prv(receiver_prvhex)
    aes_key = derive(private_key, sender_public_key)
    return aes_decrypt(aes_key, encrypted)
Ejemplo n.º 3
0
 def test_aes(self):
     data = self.big_data
     key = os.urandom(16)
     self.assertEqual(data, aes_decrypt(key, aes_encrypt(key, data)))
Ejemplo n.º 4
0
def decrypt_shared_secret(aes_key, ciphertext):
    encrypted = ciphertext[65:]
    return aes_decrypt(aes_key, encrypted)
Ejemplo n.º 5
0
 def decrypt_answer(self, answer: bytes, aes_key: bytes):
     return aes_decrypt(aes_key, answer)