Bell-Fintech / data-pan

0 stars 0 forks source link

1 #26

Open Bell-Fintech opened 1 year ago

Bell-Fintech commented 1 year ago

import yaml import subprocess import hashlib

Load the configuration from YAML file

with open('config.yaml', 'r') as config_file: config = yaml.safe_load(config_file)

Generate_Key_CONFIG = config['generate_key_config'] UPLOAD_SETTINGS = config['upload_settings']

filename = "test.csv"

def calculate_md5(file_path): hash_md5 = hashlib.md5() with open(file_path, "rb") as f: for chunk in iter(lambda: f.read(4096), b""): hash_md5.update(chunk) return hash_md5.hexdigest()

def get_curl_command(access_token, file_path, hash_md5): return [ 'curl', '-X', 'POST', '-H', f"Authorization: Bearer {access_token}", '-H', 'Content-Type: multipart/form-data', '-F', f'datasource_id={UPLOAD_SETTINGS["datasource_id"]}', '-F', f'hash_md5={hash_md5}', '-F', f'file=@{file_path}', UPLOAD_SETTINGS['upload_url'] ]

def apply_token(): url = Generate_Key_CONFIG['url'] headers = {'Content-Type': "application/json"} data = {"userName": Generate_Key_CONFIG['username'], "password": Generate_Key_CONFIG['password']} response = requests.post(url, headers=headers, data=json.dumps(data)) response.raise_for_status() response_json = response.json() access_token = response_json['data']['access_token'] return access_token

def upload_file(file_path, access_token): hash_md5 = calculate_md5(file_path) curl_command = get_curl_command(access_token, file_path, hash_md5)

process = subprocess.Popen(curl_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()

if process.returncode == 0:
    print('File uploaded successfully.')
    print(stdout.decode())
else:
    print('An error occurred during file upload.')
    print(stderr.decode())

Main execution

def main(): try: access_token = apply_token() upload_file(filename, access_token) except requests.exceptions.HTTPError as http_err: print(f'HTTP error occurred: {http_err}') except Exception as err: print(f'An error occurred: {err}')

if name == "main": main()

Bell-Fintech commented 1 year ago

和余项编码(Residue Number System, RNS)来实现秘密共享。该协议具有高效性和可扩展性,并且可以应用于云计算等领域。

另外,还有一些研究者探索使用神经网络来实现PSS协议。例如,Bouraoui等人在2021年提出了一种基于神经网络的PSS协议,其中使用了多层感知器和反向传播算法。该协议不仅具有高安全性,而且可以实现在线的秘密共享。

总之,基于两方的多项式秘密分享协议是一种重要的保密技术,在信息安全、隐私保护、云计算等领域有着广泛的应用前景。随着各种数学工具和技术的不断发展,PSS协议也不断得到改进和完善,为保护秘密提供了更加可靠和高效的方案。