本文整理汇总了Python中anon_crypto.AnonCrypto.decrypt_with_rsa方法的典型用法代码示例。如果您正苦于以下问题:Python AnonCrypto.decrypt_with_rsa方法的具体用法?Python AnonCrypto.decrypt_with_rsa怎么用?Python AnonCrypto.decrypt_with_rsa使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anon_crypto.AnonCrypto
的用法示例。
在下文中一共展示了AnonCrypto.decrypt_with_rsa方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: shuffle_and_decrypt
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import decrypt_with_rsa [as 别名]
def shuffle_and_decrypt(self):
random.shuffle(self.data_in)
self.debug("Shuffling len = %d" % len(self.data_in))
self.data_out = []
for ctuple in self.data_in:
(rem_round, ctext) = marshal.loads(ctuple)
if rem_round != self.round_id:
raise RuntimeError, "Mismatched round numbers (mine:%d, other:%d)" % (self.round_id, rem_round)
new_ctext = AnonCrypto.decrypt_with_rsa(self.key1, ctext)
pickled = marshal.dumps((self.round_id, new_ctext))
self.data_out.append(pickled)
示例2: decrypt_ciphers
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import decrypt_with_rsa [as 别名]
def decrypt_ciphers(self, keyset):
priv_keys = {}
for item in keyset:
""" Verify signature on each key """
item_str = AnonCrypto.verify(self.pub_keys, item)
(r_id, r_roundid, r_keystr) = marshal.loads(item_str)
if r_roundid != self.round_id:
raise RuntimeError, 'Mismatched round numbers'
priv_keys[r_id] = AnonCrypto.priv_key_from_str(r_keystr)
plaintexts = []
for cipher in self.final_ciphers:
(r_round, cipher_prime) = marshal.loads(cipher)
if r_round != self.round_id:
raise RuntimeError, 'Mismatched round ids'
for i in xrange(0, self.n_nodes):
cipher_prime = AnonCrypto.decrypt_with_rsa(priv_keys[i], cipher_prime)
plaintexts.append(self.unpackage_msg(cipher_prime))
self.anon_data = plaintexts
示例3: run_phase3
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import decrypt_with_rsa [as 别名]
def run_phase3(self):
self.advance_phase()
self.info("Starting data transmission phase")
self.responses = []
self.go_flag = False
"""
We put all of the pseudo-random strings in a tar file
for transmission.
"""
handle, self.tar_filename = tempfile.mkstemp()
tar = tarfile.open(name=self.tar_filename, mode="w") # Create new archive
# dereference = True)
""" For each transmission slot... """
for i in xrange(0, self.n_nodes):
debug("Processing data for msg slot %d" % i)
slot_data = self.msg_data[i]
msg_len = slot_data[0]
enc_seeds = slot_data[1]
hashes = slot_data[2]
if enc_seeds[self.id] == self.my_seed:
""" If this is my seed, use the cheating message. """
self.go_flag = True
self.responses.append(self.dfilename)
tar.add(self.cip_file, "%d" % (self.id))
else:
""" If this is not my msg slot, decrypt seed assigned to me. """
seed = AnonCrypto.decrypt_with_rsa(self.key1, enc_seeds[self.id])
h_val, fname = self.generate_prng_file(seed, msg_len)
if h_val != hashes[self.id]:
for q in xrange(0, len(hashes)):
self.debug("> %d - %s" % (q, hashes[q]))
raise RuntimeError, "Mismatched hash values"
"""
Label each file in the tar with this node's id so that nodes can
match the files to the message hashes.
"""
tar.add(fname, "%d" % (self.id))
tar.close()
if not self.go_flag:
raise RuntimeError, "My ciphertext is missing"
if self.am_leader():
fnames = AnonNet.recv_file_from_n(self.sockets)
fnames.append(self.tar_filename)
self.message_tar = self.generate_msg_tar(fnames)
""" Broadcast final messages """
self.debug("Broadcasting msg tar")
self.broadcast_file_to_all_nodes(self.message_tar)
self.debug("Sent msg tar")
else:
AnonNet.send_file_to_sock(self.leader_socket, self.tar_filename)
self.debug("Waiting for msg tar")
self.message_tar = AnonNet.recv_file_from_sock(self.leader_socket)
self.debug("Got for msg tar")