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


Python SigningKey.generate方法代码示例

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


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

示例1: test_dhZ

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import generate [as 别名]
    def test_dhZ(self):
        from ecdsa.keys import SigningKey   # VerifyingKey
        from ecdsa.curves import NIST521p

        # Party V(recepient) declares a satic key pair
        curve = NIST521p
        v_stc = SigningKey.generate(curve=curve)

        # and advertise to Party U(Sender) ( U <--(pub key)-- V)
        v_pub = v_stc.get_verifying_key()
        self.assertEqual(v_pub.curve, curve)
        print(v_pub.curve)

        # Party U provides a ephemeral key
        u_epk = SigningKey.generate(curve=v_pub.curve)

        from jose.jwa import ec
        # Compute ECDH as shared secret
        # This shared secret itself is NOT have to be exchanged.
        shared_secret_u = ec.ecdsa_dhZ(v_pub, u_epk)

        # Party V recive Epemeral Public Key ( U --(pub key)--> V)
        v_epk = u_epk.get_verifying_key()

        # Party V compute
        shared_secret_v = ec.ecdsa_dhZ(v_epk, v_stc)

        # Secrete Agreeed!
        self.assertEqual(shared_secret_u, shared_secret_v)
开发者ID:hdknr,项目名称:jose,代码行数:31,代码来源:test_ec.py

示例2: setUp

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import generate [as 别名]
 def setUp(self):
     self.private_key = SigningKey.generate()
     self.public_keys = tuple(PublicKey.from_signing_key(SigningKey.generate()) for _ in range(2))
     self.operation = Operation(OperationRev(), 'http://example.com', self.public_keys)
     sign_object(PublicKey.from_signing_key(self.private_key), self.private_key, self.operation)
     self.uuid = self.operation.uuid
     self.identifier = Identifier.from_operation(self.operation)
开发者ID:CeON,项目名称:pmpi,代码行数:9,代码来源:test_identifier.py

示例3: setUp

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import generate [as 别名]
    def setUp(self):
        initialise_database('test_database_file')

        self.private_keys = [SigningKey.generate(), SigningKey.generate()]
        self.public_keys = [PublicKey.from_signing_key(private_key) for private_key in self.private_keys]

        self.operation = [
            Operation(OperationRev(), 'http://example.com/', [self.public_keys[1]]),
            Operation(OperationRev(), 'http://example2.com/', [self.public_keys[0], self.public_keys[1]]),
            Operation(OperationRev(), 'http://example3.com/', [self.public_keys[1]])
        ]
开发者ID:CeON,项目名称:pmpi,代码行数:13,代码来源:test_operation.py

示例4: test_new_keys

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import generate [as 别名]
    def test_new_keys(self):
        user = User.new_keys(curve=NIST256p)

        self.assertIsInstance(user, User)
        self.assertIsInstance(user._private_key, SigningKey)
        self.assertIsInstance(user._public_key.verifying_key, VerifyingKey)

        self.assertEqual(user._private_key.to_der(),
                         SigningKey.from_string(user._private_key.to_string(), NIST256p).to_der())

        self.assertEqual(len(user._private_key.to_der()), len(SigningKey.generate(curve=NIST256p).to_der()))
        self.assertNotEqual(len(user._private_key.to_der()), len(SigningKey.generate().to_der()))
开发者ID:CeON,项目名称:pmpi,代码行数:14,代码来源:test_user.py

示例5: test_exchage

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import generate [as 别名]
    def test_exchage(self):
        from ecdsa import SigningKey, NIST521p

        alice_own = SigningKey.generate(curve=NIST521p)
        bob_own = SigningKey.generate(curve=NIST521p)

        alice_pri = alice_own.privkey
        alice_pub = alice_pri.public_key

        bob_pri = bob_own.privkey
        bob_pub = bob_pri.public_key

        alice_pub_point = alice_pub.point
        bob_pub_point = bob_pub.point

        print(alice_pub_point, bob_pub_point)
开发者ID:hdknr,项目名称:jose,代码行数:18,代码来源:test_ec.py

示例6: test_generate

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import generate [as 别名]
    def test_generate(self):
        def hexdigest(digester, data):
            import hashlib
            return hashlib.new(digester, data).hexdigest()

        def longdigest(digester, data):
            return int(hexdigest(digester, data), 16)

        from ecdsa.keys import SigningKey, VerifyingKey
        from ecdsa.curves import NIST521p

        pri = SigningKey.generate(curve=NIST521p)
        pub = pri.get_verifying_key()
        self.assertTrue(isinstance(pub, VerifyingKey))

        data = 'what a wonderfull world.'
        digest = longdigest('sha256', b(data))

        sig = pri.sign_number(digest)
        self.assertTrue(isinstance(sig, tuple))
        self.assertEqual(len(sig), 2)

        from ecdsa.ecdsa import Signature
        sigobj = Signature(*sig)        # (r, s)
        self.assertTrue(pub.pubkey.verifies(digest, sigobj))
开发者ID:hdknr,项目名称:jose,代码行数:27,代码来源:test_ec.py

示例7: test_no_database

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import generate [as 别名]
    def test_no_database(self):
        with self.assertRaisesRegex(pmpi.database.Database.InitialisationError, "initialise database first"):
            Block.get_ids_list()

        with self.assertRaisesRegex(pmpi.database.Database.InitialisationError, "initialise database first"):
            Block.get(sha256(b'something').digest())

        private_key = SigningKey.generate()
        public_key = PublicKey.from_signing_key(private_key)

        operations = [
            Operation(OperationRev(), 'http://example0.com/', [public_key]),
            Operation(OperationRev(), 'http://example1.com/', [public_key])
        ]

        for op in operations:
            sign_object(public_key, private_key, op)

        block = Block.from_operations_list(BlockRev(), int(time.time()), operations)
        block.mine()
        sign_object(public_key, private_key, block)

        with self.assertRaisesRegex(pmpi.database.Database.InitialisationError, "initialise database first"):
            block.put()

        with self.assertRaisesRegex(pmpi.database.Database.InitialisationError, "initialise database first"):
            block.remove()
开发者ID:CeON,项目名称:pmpi,代码行数:29,代码来源:test_block.py

示例8: new_keys

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import generate [as 别名]
    def new_keys(cls, curve=NIST192p):  # TODO different curve as default?
        """
        Create new user using auto-generated keys.

        :param curve: private key's generation curve
        """
        return cls(SigningKey.generate(curve=curve))
开发者ID:CeON,项目名称:pmpi,代码行数:9,代码来源:user.py

示例9: setUp

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import generate [as 别名]
    def setUp(self):
        self.private_key = SigningKey.generate()
        self.public_key = PublicKey.from_signing_key(self.private_key)

        self.operations = [Operation(
            OperationRev(), 'http://example.com/', [self.public_key]) for _ in range(Block.MIN_OPERATIONS + 1)]
        for op in self.operations:
            sign_object(self.public_key, self.private_key, op)
开发者ID:CeON,项目名称:pmpi,代码行数:10,代码来源:test_block.py

示例10: generate_key

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import generate [as 别名]
def generate_key(identifier):
    from brave.core.application.model import Application
    
    key = SigningKey.generate(NIST256p, hashfunc=sha256)
    Application.objects(
            id = identifier,
            key__private = None  # Make sure we don't override an existing one.
        ).update(
            set__key__private = hexlify(key.to_string())
        )
开发者ID:Acen,项目名称:core,代码行数:12,代码来源:signal.py

示例11: test_no_database

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import generate [as 别名]
    def test_no_database(self):
        with self.assertRaisesRegex(pmpi.database.Database.InitialisationError, "initialise database first"):
            Operation.get_ids_list()

        with self.assertRaisesRegex(pmpi.database.Database.InitialisationError, "initialise database first"):
            Operation.get(sha256(b'something').digest())

        operation = Operation(OperationRev(), 'http://example.com/', [])
        sk = SigningKey.generate()
        sign_object(PublicKey.from_signing_key(sk), sk, operation)

        with self.assertRaisesRegex(pmpi.database.Database.InitialisationError, "initialise database first"):
            operation.put(BlockRev())

        with self.assertRaisesRegex(pmpi.database.Database.InitialisationError, "initialise database first"):
            operation.remove(BlockRev())
开发者ID:CeON,项目名称:pmpi,代码行数:18,代码来源:test_operation.py

示例12: __init__

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import generate [as 别名]
 def __init__(self):
     # Load our keys into a usable form.
     try:
         config['api.private'] = SigningKey.from_string(unhexlify(config['api.private']), curve=NIST256p, hashfunc=sha256)
         config['api.public'] = VerifyingKey.from_string(unhexlify(config['api.public']), curve=NIST256p, hashfunc=sha256)
     except:
         log.critical("Core Service API identity, public, or private key missing.")
         
         private = SigningKey.generate(NIST256p, hashfunc=sha256)
         
         log.critical("Here's a new private key; update the api.private setting to reflect this.\n%s", private.to_string().encode('hex'))
         log.critical("Here's that key's public key; this is what you register with Core.\n%s",  private.get_verifying_key().to_string().encode('hex'))
         log.critical("After registering, save the server's public key to api.public and your service's ID to api.identity.")
         
         exit(-1)
     
     super(StartupMixIn, self).__init__()
开发者ID:Acidity,项目名称:irc,代码行数:19,代码来源:util.py

示例13: test_no_database

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import generate [as 别名]
    def test_no_database(self):
        with self.assertRaisesRegex(pmpi.database.Database.InitialisationError, "initialise database first"):
            Identifier.get_uuid_list()

        with self.assertRaisesRegex(pmpi.database.Database.InitialisationError, "initialise database first"):
            Identifier.get(uuid4())

        operation = Operation(OperationRev(), 'http://example.com/', [])
        sk = SigningKey.generate()
        sign_object(PublicKey.from_signing_key(sk), sk, operation)
        identifier = Identifier.from_operation(operation)

        with self.assertRaisesRegex(pmpi.database.Database.InitialisationError, "initialise database first"):
            identifier.put()

        with self.assertRaisesRegex(pmpi.database.Database.InitialisationError, "initialise database first"):
            identifier.remove()
开发者ID:CeON,项目名称:pmpi,代码行数:19,代码来源:test_identifier.py

示例14: config

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import generate [as 别名]
def config():
    # Load and validate the format of our auth config data
    try:
        config['api.identity']
        config['api.private'] = SigningKey.from_string(unhexlify(config['api.private']), curve=NIST256p, hashfunc=sha256)
        config['api.public'] = VerifyingKey.from_string(unhexlify(config['api.public']), curve=NIST256p, hashfunc=sha256)
    except:
        private = SigningKey.generate(NIST256p, hashfunc=sha256)

        error_message = "Core Service API identity, public, or private key missing.<br /><br />\n\n"

        error_message += "Here's a new private key; update the api.private setting to reflect this.<br />\n" + \
                         "%s <br /><br />\n\n" % private.to_string().encode('hex')

        error_message += "Here's that key's public key; this is what you register with Core.<br />\n" + \
                         "%s <br /><br /><br />\n\n" % private.get_verifying_key().to_string().encode('hex')

        error_message += "After registering, save the server's public key to api.public " + \
                         "and your service's ID to api.identity.<br /><br />"

        return error_message

    # config data looks good, allow auth attempt
    return '<a href="'+url_for('authorize')+'">Click here to auth</a>'
开发者ID:damienb,项目名称:core-api-hello-world,代码行数:26,代码来源:hello.py

示例15: check_app

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import generate [as 别名]
    def check_app(app):
        try:
            for var in CoreAPI.required_config_variables_:
                app.config[var]
        except KeyError as e:
            private = SigningKey.generate(NIST256p, hashfunc=sha256)

            error_message =  "\n================================================================================\n"

            error_message += "Core Service API identity, public, or private key missing.\n\n"

            error_message += "Here's a new private key; update the api.private setting to reflect this.\n" + \
                             "%s \n\n" % private.to_string().encode('hex')

            error_message += "Here's that key's public key; this is what you register with Core.\n" + \
                             "%s \n\n" % private.get_verifying_key().to_string().encode('hex')

            error_message += textwrap.fill("After registering, make sure to populate all of the following in config.py: {0}" \
                                 .format(", ".join(CoreAPI.required_config_variables_)))
                             
            error_message += "\n================================================================================\n\n"
        
            print error_message
            raise
开发者ID:damienb,项目名称:standings,代码行数:26,代码来源:coreapi.py


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