csv_data
alice
import pandas as pd
alice_df = pd.DataFrame({
"name": ["mike", "tony", "john", "kate"],"age": [15,13,20,21]})
alice_df.to_csv(f"./alice_psi_inputt.csv", index=False)
bob
import pandas as pd
bob_df = pd.DataFrame({
"name": ["alice", "tony", "john", "kitty"],"age": [15,13,20,21]})
bob_df.to_csv(f"./bob_psi_inputt.csv", index=False)
PSI
https://www.secretflow.org.cn/zh-CN/docs/psi/v0.2.0beta/getting_started
PSI_v1
alice
import spu
import secretflow as sf
cluster_config ={
'parties':{
'alice':{
'address': '172.17.0.3:52000',
'listen_addr': '0.0.0:52000'
},
'bob':{
'address':'172.17.0.4:52000',
'listen_addr': '0.0.0:52000'
}
},
'self_party':'alice'
}
sf.shutdown()
sf.init(address='local',cluster_config=cluster_config)
alice = sf.PYU('alice')
bob = sf.PYU('bob')
cluster_def={
"nodes":[{
"party": "alice", "address": "172.17.0.3:41805"},
{
"party":"bob", "address": "172.17.0.4:52397"},],
"runtime_config":{
"protocol": spu.spu_pb2.SEMI2K,
"field": spu.spu_pb2.FM128,
}
}
spu = sf.SPU(cluster_def, link_desc={
"connect_retry_times": 60, "connect_retry_interval_ms":1000,})
spu.psi_csv(
key={
alice:["name"],bob:["name"]},
input_path={
alice:f"/root/psi/data/alice_psi_input.csv", bob:f"/root/psi/data/bob_psi_input.csv"},
output_path={
alice:f"/root/psi/data/alice_psi_output.csv",bob:f"/root/psi/data/bob_psi_outpuut.csv"},
receiver="alice",
broadcast_result=True,
protocol="ECDH_PSI_2PC",
curve_type="CURVE_25519")
bob
import spu
import secretflow as sf
cluster_config ={
'parties':{
'alice':{
'address': '172.17.0.3:52000',
'listen_addr': '0.0.0:52000'
},
'bob':{
'address':'172.17.0.4:52000',
'listen_addr': '0.0.0:52000'
}
},
'self_party':'bob'
}
sf.shutdown()
sf.init(address='local',cluster_config=cluster_config)
alice = sf.PYU('alice')
bob = sf.PYU('bob')
cluster_def={
"nodes":[{
"party": "alice", "address": "172.17.0.3:41805"},
{
"party": "bob", "address": "172.17.0.4:52397"}],
"runtime_config":{
"protocol": spu.spu_pb2.SEMI2K,
"field": spu.spu_pb2.FM128
}
}
spu = sf.SPU(cluster_def, link_desc={
"connect_retry_times": 60, "connect_retry_interval_ms":1000,})
print(dir(spu))
spu.psi_csv(
key={
alice:["name"],bob:["name"]},
input_path={
alice:f"/root/psi/data/alice_psi_input.csv", bob:f"/root/psi/data/bob_psi_input.csv"},
output_path={
alice:f"/root/psi/data/alice_psi_output.csv",bob:f"/root/psi/data/bob_psi_outpuut.csv"},
receiver="alice",
broadcast_result=True,
protocol="ECDH_PSI_2PC",
curve_type="CURVE_25519")
PSI_v2
alice
import spu
import secretflow as sf
cluster_config ={
'parties':{
'alice':{
'address': '172.17.0.3:52000',
'listen_addr': '0.0.0:52000'
},
'bob':{
'address':'172.17.0.4:52000',
'listen_addr': '0.0.0:52000'
}
},
'self_party':'alice'
}
sf.shutdown()
sf.init(address='local',cluster_config=cluster_config)
cluster_def={
"nodes":[{
"party": "alice", "address": "172.17.0.3:41805"},
{
"party":"bob", "address": "172.17.0.4:52397"},],
"runtime_config":{
"protocol": spu.spu_pb2.SEMI2K,
"field": spu.spu_pb2.FM128,
}
}
spu = sf.SPU(cluster_def, link_desc={
"connect_retry_times": 60, "connect_retry_interval_ms":1000,})
spu.psi_v2(
keys={
"alice":["name"],"bob":["name"]},
input_path={
"alice":f"/root/psi/data/alice_psi_input.csv", "bob":f"/root/psi/data/bob_psi_input.csv"},
output_path={
"alice":f"/root/psi/data/alice_psi_output.csv","bob":f"/root/psi/data/bob_psi_outpuut.csv"},
receiver="alice",
broadcast_result=True,
protocol="PROTOCOL_ECDH",
ecdh_curve="CURVE_25519")
bob
import spu
import secretflow as sf
cluster_config ={
'parties':{
'alice':{
'address': '172.17.0.3:52000',
'listen_addr': '0.0.0:52000'
},
'bob':{
'address':'172.17.0.4:52000',
'listen_addr': '0.0.0:52000'
}
},
'self_party':'bob'
}
sf.shutdown()
sf.init(address='local',cluster_config=cluster_config)
cluster_def={
"nodes":[{
"party": "alice", "address": "172.17.0.3:41805"},
{
"party": "bob", "address": "172.17.0.4:52397"}],
"runtime_config":{
"protocol": spu.spu_pb2.SEMI2K,
"field": spu.spu_pb2.FM128
}
}
spu = sf.SPU(cluster_def, link_desc={
"connect_retry_times": 60, "connect_retry_interval_ms":1000,})
spu.psi_v2(
keys={
"alice":["name"],"bob":["name"]},
input_path={
"alice":f"/root/psi/data/alice_psi_input.csv", "bob":f"/root/psi/data/bob_psi_input.csv"},
output_path={
"alice":f"/root/psi/data/alice_psi_output.csv","bob":f"/root/psi/data/bob_psi_outpuut.csv"},
receiver="alice",
broadcast_result=True,
protocol="PROTOCOL_ECDH",
ecdh_curve="CURVE_25519")