def decryptMessage(msg, keys):
    ciphertext = msg.encrypted_message.ciphertext
    nonce = msg.encrypted_message.nonce
    try:
        plaintextBytes = nacl.bindings.crypto_secretbox_open(
            ciphertext, nonce, keys[0])
        decrypted = nstp_v4_pb2.DecryptedMessage()
        decrypted.ParseFromString(plaintextBytes)
        print("DECRYPTED MESSAGE\n", decrypted)
        return decrypted
    except nacl.exceptions.CryptoError:
        print("Bad key")
        return error_message("Failed to decrypt given message")
def ping_response(data):
    response = nstp_v4_pb2.DecryptedMessage()
    response.ping_response.hash = data
    return response
def load_response(value):
    response = nstp_v4_pb2.DecryptedMessage()
    response.load_response.value = value
    return response
def store_response(hashedValue):
    response = nstp_v4_pb2.DecryptedMessage()
    response.store_response.hash = hashedValue
    response.store_response.hash_algorithm = 0
    return response
def authentication_response(decision, user, authenticated):
    response = nstp_v4_pb2.DecryptedMessage()
    response.auth_response.authenticated = decision
    return response, user, authenticated