当前位置: 首页>>代码示例>>Python>>正文


Python AnonCrypto.encrypt_with_rsa方法代码示例

本文整理汇总了Python中anon_crypto.AnonCrypto.encrypt_with_rsa方法的典型用法代码示例。如果您正苦于以下问题:Python AnonCrypto.encrypt_with_rsa方法的具体用法?Python AnonCrypto.encrypt_with_rsa怎么用?Python AnonCrypto.encrypt_with_rsa使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在anon_crypto.AnonCrypto的用法示例。


在下文中一共展示了AnonCrypto.encrypt_with_rsa方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_cipher_string

# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import encrypt_with_rsa [as 别名]
	def create_cipher_string(self):
		self.cipher_prime = self.datum_string()
		""" Encrypt with all secondary keys from N ... 1 """
		self.debug("Orig len: %d" % len(self.cipher_prime))
		
		for i in xrange(self.n_nodes - 1, -1, -1):
			k1, k2 = self.pub_keys[i]
			self.cipher_prime = AnonCrypto.encrypt_with_rsa(k2, self.cipher_prime)
			self.debug("Cipher-prim len: %d" % len(self.cipher_prime))

		self.cipher = self.cipher_prime

		""" Encrypt with all primary keys from N ... 1 """
		for i in xrange(self.n_nodes-1, -1, -1):
			k1, k2 = self.pub_keys[i]
			self.cipher = AnonCrypto.encrypt_with_rsa(k1, self.cipher)
			self.debug("Cipher len: %d" % len(self.cipher))
开发者ID:ASchurman,项目名称:Dissent,代码行数:19,代码来源:shuffle_node.py

示例2: run_phase1

# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import encrypt_with_rsa [as 别名]
    def run_phase1(self):
        self.seeds = []
        self.gens = []
        self.my_hashes = []
        for i in xrange(0, self.n_nodes):
            seed = AnonCrypto.random_seed()
            self.seeds.append(seed)
            self.gens.append(AnonRandom(seed))

        self.msg_len = os.path.getsize(self.msg_file)
        (handle, self.cip_file) = tempfile.mkstemp()

        blocksize = 8192

        """
		The hash h holds a hash of the XOR of all
		pseudo-random strings with the author's message.
		"""
        h = M2Crypto.EVP.MessageDigest("sha1")

        """ Hash of final message """
        h_msg = M2Crypto.EVP.MessageDigest("sha1")
        self.debug("Starting to write data file")

        with open(self.msg_file, "r") as f_msg:
            with open(self.cip_file, "w") as f_cip:
                """ Loop until we reach EOF """
                while True:
                    block = f_msg.read(blocksize)
                    h_msg.update(block)
                    n_bytes = len(block)
                    if n_bytes == 0:
                        break

                    """
					Get blocksize random bytes for each other node
					and XOR them together with blocksize bytes of
					my message, update the hash and write the XOR'd
					block out to disk.
					"""
                    for i in xrange(0, self.n_nodes):
                        """ Don't XOR bits for self """
                        if i == self.id:
                            continue

                        r_bytes = self.gens[i].rand_bytes(n_bytes)
                        # self.debug("l1: %d, l2: %d, n: %d" % (len(block), len(r_bytes), n_bytes))
                        block = Utilities.xor_bytes(block, r_bytes)
                    f_cip.write(block)
                    h.update(block)

        self.debug("Finished writing my data file")

        """ Encrypt each of the pseudo-random generator seeds. """
        self.enc_seeds = []
        for i in xrange(0, self.n_nodes):
            self.my_hashes.append(self.gens[i].hash_value())
            # Encrypt each seed with recipient's primary pub key
            self.enc_seeds.append(AnonCrypto.encrypt_with_rsa(self.pub_keys[i][0], self.seeds[i]))

        self.my_msg_hash = h_msg.final()

        """ Insert "cheating" hash for self. """
        self.my_hashes[self.id] = h.final()

        """ Remember the seed encrypted for self. """
        self.my_seed = self.enc_seeds[self.id]

        """ Write all the data to be sent out to disk. """
        (dhandle, self.dfilename) = tempfile.mkstemp()
        with open(self.dfilename, "w") as f:
            marshal.dump((self.id, self.round_id, self.msg_len, self.my_msg_hash, self.enc_seeds, self.my_hashes), f)
        return
开发者ID:ecrypto,项目名称:dissent,代码行数:75,代码来源:bulk_node.py


注:本文中的anon_crypto.AnonCrypto.encrypt_with_rsa方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。