本文整理汇总了Python中anon_crypto.AnonCrypto.pub_key_to_str方法的典型用法代码示例。如果您正苦于以下问题:Python AnonCrypto.pub_key_to_str方法的具体用法?Python AnonCrypto.pub_key_to_str怎么用?Python AnonCrypto.pub_key_to_str使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anon_crypto.AnonCrypto
的用法示例。
在下文中一共展示了AnonCrypto.pub_key_to_str方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: recv_interest_voucher
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import pub_key_to_str [as 别名]
def recv_interest_voucher(self, data):
msg, key = marshal.loads(data)
(nonce, leader_ip, leader_gui_port, leader_com_port) = marshal.loads(msg)
self.DEBUG(
"Start round voucher from %s:%s, communicating at port %s" % (leader_ip, leader_gui_port, leader_com_port)
)
# get the path to the file you want to share
self.emit(SIGNAL("getSharedFilename()"))
verified = self.verify(leader_ip, leader_gui_port, data)
""" generate temporary keys for this round so leader can aggregate """
self.gen_temp_keys()
temp1_str = AnonCrypto.pub_key_to_str(self.pubgenkey1)
temp2_str = AnonCrypto.pub_key_to_str(self.pubgenkey2)
""" default to random file of 128 bytes if you don't have anything to share """
if verified:
if os.path.exists(self.shared_filename):
self.DEBUG("You are sharing file %s" % (self.shared_filename))
else:
self.DEBUG("Not a valid file path, continuing without sharing...")
# respond with your interest
self.DEBUG("Verified leader, participating as %s:%s at port %s" % (self.ip, self.gui_port, self.com_port))
response = marshal.dumps((nonce, self.ip, self.gui_port, self.com_port, temp1_str, temp2_str))
cipher = AnonCrypto.sign_with_key(self.privKey, response)
AnonNet.send_to_addr(leader_ip, int(leader_gui_port), marshal.dumps(("interested", cipher)))
else:
self.DEBUG("Unkown leader, opting out...")
示例2: phase0b_msg
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import pub_key_to_str [as 别名]
def phase0b_msg(self):
""" Message the leader sends to all other nodes. """
newdict = {}
for i in xrange(0, self.n_nodes):
k1, k2 = self.pub_keys[i]
newdict[i] = (AnonCrypto.pub_key_to_str(k1), AnonCrypto.pub_key_to_str(k2))
return marshal.dumps((self.round_id, newdict))
示例3: initiate_round
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import pub_key_to_str [as 别名]
def initiate_round(self):
self.DEBUG("I initiated a dissent round! Finding collaborators...")
# get the path to the file you want to share
self.emit(SIGNAL("getSharedFilename()"))
nonce = int(1)
self.participants = []
self.distrusted_peers = []
""" generate temporary keys for this round, add to participants """
self.gen_temp_keys()
temp1_str = AnonCrypto.pub_key_to_str(self.pubgenkey1)
temp2_str = AnonCrypto.pub_key_to_str(self.pubgenkey2)
""" initiate round with a signed voucher containing relevant information """
my_voucher = marshal.dumps((nonce, self.ip, self.gui_port, self.com_port, temp1_str, temp2_str))
cipher = AnonCrypto.sign_with_key(self.privKey, my_voucher)
""" make sure you have something to share first """
if os.path.exists(self.shared_filename):
self.DEBUG("You are sharing file %s" % (self.shared_filename))
else:
self.DEBUG("Not a valid file path, share something to start a round!")
return
# add yourself as leader in the participants list (entry 0)
self.participants.append((cipher, self.ip, self.gui_port, self.com_port))
self.emit(SIGNAL("getDistrustedPeers()"))
# ask if peers are interested
interest_voucher = marshal.dumps((nonce, self.ip, self.gui_port, self.com_port))
cipher = AnonCrypto.sign_with_key(self.privKey, interest_voucher)
self.broadcast_to_all_peers(marshal.dumps(("interested?", cipher)))
# allow one minute to receive all replies, then initiate round with those peers
DelayTimer(INTEREST_WAIT, self.prepare_round).start()
示例4: peer_public_key_string
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import pub_key_to_str [as 别名]
def peer_public_key_string(self, ip, port):
hashkey = self.hash_peer(ip, port)
key = M2Crypto.RSA.load_pub_key("state/%s.pub" % hashkey)
return AnonCrypto.pub_key_to_str(key)
示例5: public_key_string
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import pub_key_to_str [as 别名]
def public_key_string(self):
return AnonCrypto.pub_key_to_str(self.pubKey)