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


Python rsa.generate函数代码示例

本文整理汇总了Python中pycryptopp.publickey.rsa.generate函数的典型用法代码示例。如果您正苦于以下问题:Python generate函数的具体用法?Python generate怎么用?Python generate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_serialize_and_deserialize_signing_key_and_test

 def test_serialize_and_deserialize_signing_key_and_test(self):
     signer = rsa.generate(KEYSIZE)
     verifier = signer.get_verifying_key()
     serstr = signer.serialize()
     signer = None
     newsigner = rsa.create_signing_key_from_string(serstr)
     self._help_test_sign_and_check(newsigner, verifier, "a")
     self._help_test_sign_and_check_random(newsigner, verifier)
     self._help_test_sign_and_failcheck(newsigner, verifier, "a")
     self._help_test_sign_and_failcheck_random(newsigner, verifier)
开发者ID:Phoul,项目名称:pycryptopp,代码行数:10,代码来源:test_rsa.py

示例2: generate

 def generate(self, keysize=None):
     """I return a Deferred that fires with a (verifyingkey, signingkey)
     pair. I accept a keysize in bits (2048 bit keys are standard, smaller
     keys are used for testing). If you do not provide a keysize, I will
     use my default, which is set by a call to set_default_keysize(). If
     set_default_keysize() has never been called, I will create 2048 bit
     keys."""
     keysize = keysize or self.default_keysize
     # RSA key generation for a 2048 bit key takes between 0.8 and 3.2
     # secs
     signer = rsa.generate(keysize)
     verifier = signer.get_verifying_key()
     return defer.succeed( (verifier, signer) )
开发者ID:tahoe-lafs,项目名称:tahoe-lafs,代码行数:13,代码来源:client.py

示例3: __init__

	def __init__(self, name ):
		PublicKey.__init__(self)
		
		key_file = os.path.join('keys', name)
		if os.path.exists(key_file):
			log.info('loading %s\'s private key'%(name,))
			self.private_key = rsa.create_signing_key_from_string( read_file(key_file) )
			if self.private_key:
				log.info('private key %s loaded'%(name,))
			else:
				log.error('invalid private key for %s'%(name,))
				raise Exception('no private key for %s'%(name,))
		else:
			log.info('genreating new private key for user %s'%(name,))
			self.private_key = rsa.generate(get_default_key_size())
			if not os.path.exists('keys'):
				os.mkdir('keys')
			write_file(key_file, self.private_key.serialize())
		
		self.public_key = self.private_key.get_verifying_key()
开发者ID:bogolt,项目名称:xmpp-db,代码行数:20,代码来源:crypto.py

示例4: generate

 def generate(self, keysize=None):
     """I return a Deferred that fires with a (verifyingkey, signingkey)
     pair. I accept a keysize in bits (2048 bit keys are standard, smaller
     keys are used for testing). If you do not provide a keysize, I will
     use my default, which is set by a call to set_default_keysize(). If
     set_default_keysize() has never been called, I will create 2048 bit
     keys."""
     keysize = keysize or self.default_keysize
     if self._remote:
         d = self._remote.callRemote('get_rsa_key_pair', keysize)
         def make_key_objs((verifying_key, signing_key)):
             v = rsa.create_verifying_key_from_string(verifying_key)
             s = rsa.create_signing_key_from_string(signing_key)
             return v, s
         d.addCallback(make_key_objs)
         return d
     else:
         # RSA key generation for a 2048 bit key takes between 0.8 and 3.2
         # secs
         signer = rsa.generate(keysize)
         verifier = signer.get_verifying_key()
         return defer.succeed( (verifier, signer) )
开发者ID:jsgf,项目名称:tahoe-lafs,代码行数:22,代码来源:client.py

示例5: test_sign_and_failcheck_a

 def test_sign_and_failcheck_a(self):
     signer = rsa.generate(KEYSIZE)
     verifier = signer.get_verifying_key()
     return self._help_test_sign_and_failcheck(signer, verifier, "a")
开发者ID:Phoul,项目名称:pycryptopp,代码行数:4,代码来源:test_rsa.py

示例6: test_sign_and_check_random

 def test_sign_and_check_random(self):
     signer = rsa.generate(KEYSIZE)
     verifier = signer.get_verifying_key()
     return self._help_test_sign_and_check_random(signer, verifier)
开发者ID:Phoul,项目名称:pycryptopp,代码行数:4,代码来源:test_rsa.py

示例7: test_sign

 def test_sign(self):
     signer = rsa.generate(KEYSIZE)
     result = signer.sign("abc")
     self.failUnlessEqual(len(result), ((KEYSIZE+7)/8))
开发者ID:Phoul,项目名称:pycryptopp,代码行数:4,代码来源:test_rsa.py

示例8: test_generate

 def test_generate(self):
     rsa.generate(KEYSIZE)
     # Hooray!  It didn't raise an exception!  We win!
     rsa.generate(sizeinbits=KEYSIZE)
开发者ID:Phoul,项目名称:pycryptopp,代码行数:4,代码来源:test_rsa.py

示例9: test_generate_bad_size

 def test_generate_bad_size(self):
     try:
         rsa.generate(KEYSIZE-1)
     except rsa.Error, le:
         self.failUnless("size in bits is required to be >=" in str(le), le)
开发者ID:Phoul,项目名称:pycryptopp,代码行数:5,代码来源:test_rsa.py

示例10: randstr

def randstr(n):
    return ''.join(map(chr, map(random.randrange, [0]*n, [256]*n)))

KEYSIZE=522 # 522 bits is far too few for actual security -- it is used only for faster unit tests

class Signer(unittest.TestCase):
    def test_generate_bad_size(self):
        try:
            rsa.generate(KEYSIZE-1)
        except rsa.Error, le:
            self.failUnless("size in bits is required to be >=" in str(le), le)
        else:
            self.fail("Should have raised error from size being too small.")
        try:
            rsa.generate(sizeinbits=KEYSIZE-1)
        except rsa.Error, le:
            self.failUnless("size in bits is required to be >=" in str(le), le)
        else:
            self.fail("Should have raised error from size being too small.")

    def test_generate(self):
        rsa.generate(KEYSIZE)
        # Hooray!  It didn't raise an exception!  We win!
        rsa.generate(sizeinbits=KEYSIZE)
        # Hooray!  It didn't raise an exception!  We win!

    def test_sign(self):
        signer = rsa.generate(KEYSIZE)
        result = signer.sign("abc")
        self.failUnlessEqual(len(result), ((KEYSIZE+7)/8))
开发者ID:Phoul,项目名称:pycryptopp,代码行数:30,代码来源:test_rsa.py

示例11: gen_key

 def gen_key(self, key_size):
     self.vlog('%s generating key size %s' % (self, key_size, ))
     signer = rsa.generate(key_size)
     verifier = signer.get_verifying_key()
     return verifier.serialize(), signer.serialize()
开发者ID:ClashTheBunny,项目名称:tahoe-lafs,代码行数:5,代码来源:key_generator.py

示例12: __init__

 def __init__(self):
     self.signer = rsa.generate(sizeinbits=self.SIZEINBITS)
开发者ID:bearrito,项目名称:powerhose,代码行数:2,代码来源:crypto_worker.py

示例13: gen

 def gen(self, N):
     for i in xrange(N):
          rsa.generate(sizeinbits=self.SIZEINBITS)
开发者ID:Phoul,项目名称:pycryptopp,代码行数:3,代码来源:bench_sigs.py

示例14: ver_init

 def ver_init(self, N):
     signer = rsa.generate(sizeinbits=self.SIZEINBITS)
     self.sig = signer.sign(msg)
     self.verifier = signer.get_verifying_key()
开发者ID:Phoul,项目名称:pycryptopp,代码行数:4,代码来源:bench_sigs.py

示例15: sign_init

 def sign_init(self, N):
     self.signer = rsa.generate(sizeinbits=self.SIZEINBITS)
开发者ID:Phoul,项目名称:pycryptopp,代码行数:2,代码来源:bench_sigs.py


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