Exemplo n.º 1
0
def kgc_generate_user(user_id: str):
    with (kgc_path / 'master_key').open(mode='rb') as f:
        master_key = pairing_pickle.load(group, f)

    if (kgc_path / '{}'.format(user_id)).exists():
        print('User with this id is already registered in this KGC')
    else:
        with (kgc_path / '{}'.format(user_id)).open(mode='wb') as f:
            pairing_pickle.dump(group, pre.keyGen(master_key, user_id), f)
Exemplo n.º 2
0
def reEncrypt(user, to_user, record, type_attribute):
    ciphertext = data_helper.load(user, record)

    # Retrieve the reencryption key
    with (reencryption_path /
          'from_{}_to_{}_type_{}'.format(user, to_user, type_attribute)).open(
              mode='rb') as f:
        re_encryption_key = pairing_pickle.load(group, f)

        # Reencrypt the data
    cipher = pre.reEncrypt(get_params(), re_encryption_key,
                           ciphertext[PHR.SYMKEY()])
    ciphertext[PHR.SYMKEY()] = cipher
    data_helper.save(to_user, type_attribute, ciphertext,
                     "reencryption_from_{}_{}".format(user, record))
    return cipher
Exemplo n.º 3
0
def get_params():
    with (kgc_path / 'params').open(mode='rb') as f:
        return pairing_pickle.load(group, f)
Exemplo n.º 4
0
def load_user_key(user):
    print('Loading user key: {}'.format(kgc_path / user))
    with (kgc_path / user).open(mode='rb') as f:
        user_key = pairing_pickle.load(group, f)
    return user_key