Exemple #1
0
    def encryptJsonInData(self):
        global EC_key
        global WorkloadJson_filename
        global worker_obj

        enc_json_file = asksaveasfilename()
        save_key_file = asksaveasfilename()

        json_file = open(WorkloadJson_filename, "r")
        workload_str = json_file.read()
        workload_json = json.loads(workload_str)
        workload_json["params"]["workerId"] = worker_obj.worker_id

        workload_str = json.dumps(workload_json)

        sig_obj = signature.ClientSignature()

        signing_key = signingAlgorithm.signAlgorithm()
        signing_key.loadKey(EC_key)

        session_iv = sig_obj.generate_sessioniv()

        enc_obj = encryptionAlg.encAlgorithm()
        session_key = enc_obj.generateKey()

        enc_session_key = sig_obj.generate_encrypted_key(
            session_key, worker_obj.encryption_key)

        request_json = sig_obj.generate_client_signature(
            workload_str, worker_obj, signing_key, session_key, session_iv,
            enc_session_key)

        enc_json_file = open(enc_json_file, "w")
        enc_json_file.write(request_json)

        enc_session_json = '{"key": ' + str(list(session_key)) + ',"iv": ' \
            + str(list(session_iv)) + '}'

        enc_session_key_file = open(save_key_file, "w")
        enc_session_key_file.write(enc_session_json)

        json_file.close()
        enc_json_file.close()
        enc_session_key_file.close()
Exemple #2
0
 def generate_encrypted_session_key(self, session_key,
                                    worker_encryption_key):
     session_key = encryptionAlg.encAlgorithm()
     return self.encrypt_data(worker_encryption_key.encode(),
                              session_key.generateKey(), session_iv)
Exemple #3
0
 def encrypt_data(self, data, encryption_key, iv):
     encrypt = encryptionAlg.encAlgorithm()
     return encrypt.encrypt_data(data, encryption_key, iv)