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


Python SigningKey.from_string方法代码示例

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


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

示例1: get

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import from_string [as 别名]
 def get(self):
     app = self.app
     
     if request.is_xhr:
         return 'brave.core.template.form', dict(
                 kind = _("Application"),
                 form = manage_form('/application/manage/{0}'.format(app.id)),
                 data = dict(
                         name = app.name,
                         description = app.description,
                         site = app.site,
                         contact = app.contact,
                         development = app.development,
                         key = dict(
                                 public = app.key.public,
                                 private = app.key.private,
                             ),
                         required = app.mask.required,
                         optional = app.mask.optional,
                         groups = app.groups
                     )
             )
     
     key = SigningKey.from_string(unhexlify(app.key.private), curve=NIST256p, hashfunc=sha256)
     return 'brave.core.application.template.view_app', dict(
             app = app,
             key = hexlify(key.get_verifying_key().to_string()),
             pem = key.get_verifying_key().to_pem()
         )
开发者ID:Acen,项目名称:core,代码行数:31,代码来源:manage.py

示例2: setUp

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

        self.patcher1 = patch("addressimo.util.get_id")
        self.patcher2 = patch("addressimo.util.create_json_response")
        self.patcher3 = patch("addressimo.util.request")
        self.patcher4 = patch("addressimo.util.VerifyingKey", wraps=VerifyingKey)

        self.mockGetId = self.patcher1.start()
        self.mockCreateJsonResponse = self.patcher2.start()
        self.mockRequest = self.patcher3.start()
        self.mockVerifyingKey = self.patcher4.start()

        self.mockRequest.url = "http://addressimo.com/address/0123456789abcdef/sf"
        self.mockRequest.data = "this is some crazy random data, dude! you know you gotta love this!"

        from ecdsa.keys import SigningKey
        from ecdsa.curves import SECP256k1

        self.sk = SigningKey.from_string(TEST_PRIVKEY.decode("hex"), curve=SECP256k1)
        sig = self.sk.sign(self.mockRequest.url + self.mockRequest.data, hashfunc=sha256, sigencode=sigencode_der)

        self.mockRequest.headers = {
            "x-identity": VerifyingKey.from_string(TEST_PUBKEY.decode("hex"), curve=curves.SECP256k1)
            .to_der()
            .encode("hex"),
            "x-signature": sig.encode("hex"),
        }

        self.mockIdObj = Mock()
        self.mockIdObj.auth_public_key = TEST_PUBKEY

        # Mock the decorator function -> We run self.decorated
        self.mock_func = MagicMock(return_value="fake_response")
        self.mock_func.__name__ = "mock_func"
        self.decorated = requires_valid_signature(self.mock_func)
开发者ID:netkicorp,项目名称:addressimo,代码行数:37,代码来源:test_util.py

示例3: _get_brave_api

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import from_string [as 别名]
def _get_brave_api():
    config = app.config['BRAVE_AUTH']
    return API(config['endpoint'],
               config['identity'],
               SigningKey.from_string(unhexlify(config['private']),
                                      curve=NIST256p, hashfunc=sha256),
               VerifyingKey.from_string(unhexlify(config['public']),
                                        curve=NIST256p, hashfunc=sha256))
开发者ID:drakedevel,项目名称:eveposcal,代码行数:10,代码来源:auth.py

示例4: authorized

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import from_string [as 别名]
def authorized():
    # Perform the initial API call and direct the user.

    # Convert Key text into objects
    config['api.private'] = SigningKey.from_string(unhexlify(config['api.private']), curve=NIST256p, hashfunc=sha256)
    config['api.public'] = SigningKey.from_string(unhexlify(config['api.public']), curve=NIST256p, hashfunc=sha256)

    # Build API Client for CORE Services
    api = API(config['api.endpoint'], config['api.identity'], config['api.private'], config['api.public'])

    # Build Success/Failure Redirect URLs
    token = request.args.get('token', '')

    if token == '':
        abort(401)

    # Make the authentication call to the CORE Service
    result = api.core.info(token=token)

    return jsonify(result)
开发者ID:damienb,项目名称:core-api-hello-world,代码行数:22,代码来源:hello.py

示例5: __init__

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import from_string [as 别名]
 def __init__(self, app):
     self.endpoint = app.config['CORE_ENDPOINT']
     self.app_id = app.config['CORE_APP_ID']
     self.private_key_string = app.config['CORE_PRIVATE_KEY']
     self.core_public_key_string = app.config['CORE_CORE_PUBLIC_KEY']
     
     self.private_key = SigningKey.from_string(unhexlify(self.private_key_string), curve=NIST256p, hashfunc=sha256)
     self.core_public_key = VerifyingKey.from_string(unhexlify(self.core_public_key_string), curve=NIST256p, hashfunc=sha256)
     
     self.view_perm = app.config['CORE_VIEW_PERMISSION']
     self.edit_perm = app.config['CORE_EDIT_PERMISSION']
开发者ID:damienb,项目名称:standings,代码行数:13,代码来源:coreapi.py

示例6: __init__

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import from_string [as 别名]
 def __init__(self):
     from brave.mumble import util
     
     # Configure mail delivery services.
     util.mail = Mailer(config, 'mail')
     util.mail.start()
     
     # Load our keys into a usable form.
     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)
     
     super(StartupMixIn, self).__init__()
开发者ID:Acidity,项目名称:jabber-auth,代码行数:14,代码来源:util.py

示例7: test_new_keys

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import from_string [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

示例8: get_brave_api

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import from_string [as 别名]
def get_brave_api():
    import braveapi.client
    from binascii import unhexlify
    from hashlib import sha256
    from ecdsa.keys import SigningKey, VerifyingKey
    from ecdsa.curves import NIST256p

    endpoint = config.braveapi_endpoint
    my_id = config.braveapi_my_id
    my_privkey = SigningKey.from_string(unhexlify(config.braveapi_my_privkey), curve=NIST256p, hashfunc=sha256)
    server_pubkey = VerifyingKey.from_string(unhexlify(config.braveapi_server_pubkey), curve=NIST256p, hashfunc=sha256)

    return braveapi.client.API(endpoint, my_id, my_privkey, server_pubkey)
开发者ID:eve-val,项目名称:contract-watcher,代码行数:15,代码来源:main.py

示例9: __after__

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import from_string [as 别名]
 def __after__(self, result, *args, **kw):
     """Generate the JSON response and sign."""
     
     key = SigningKey.from_string(unhexlify(request.service.key.private), curve=NIST256p, hashfunc=sha256)
     
     response = Response(status=200, charset='utf-8')
     response.date = datetime.utcnow()
     response.last_modified = result.pop('updated', None)
     
     ct, body = render('json:', result)
     response.headers[b'Content-Type'] = str(ct)  # protect against lack of conversion in Flup
     response.body = body
     
     canon = "{req.service.id}\n{resp.headers[Date]}\n{req.url}\n{resp.body}".format(
                 req = request,
                 resp = response
开发者ID:Acidity,项目名称:api,代码行数:18,代码来源:controller.py

示例10: GET

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

        try:
            private = SigningKey.from_string(unhexlify(settings['api']['private']), curve=NIST256p, hashfunc=sha256)
            public = VerifyingKey.from_string(unhexlify(settings['api']['public']), curve=NIST256p, hashfunc=sha256)
        except:
            return "Invalid keys"
        # Perform the initial API call and direct the user.
        api = API(settings['api']['endpoint'], settings['api']['identity'], private, public)

        success = str(settings['domain'] + settings['path'] + '/account/authorized')
        failure = str(settings['domain'] + settings['path'] + '/account/nolove')

        result = api.core.authorize(success=success, failure=failure)

        raise web.seeother(result.location, absolute=True)
开发者ID:BraveNewbies,项目名称:notes,代码行数:18,代码来源:controller.py

示例11: __init__

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import from_string [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

示例12: authorize

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import from_string [as 别名]
def authorize():

    # Convert Key text into objects
    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)

    # Build API Client for CORE Services
    api = API(config['api.endpoint'], config['api.identity'], config['api.private'], config['api.public'])

    # Build Success/Failure Redirect URLs
    success = str("http://"+app.config['SERVER_NAME']+url_for('authorized'))
    failure = str("http://"+app.config['SERVER_NAME']+url_for('fail'))

    # Make the authentication call to the CORE Service
    result = api.core.authorize(success=success, failure=failure)

    # Redirect based on the authentication request validity
    return redirect(result.location)
开发者ID:damienb,项目名称:core-api-hello-world,代码行数:20,代码来源:hello.py

示例13: authenticate

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import from_string [as 别名]
    def authenticate(self, identifier, password=None):
        """Validate the given identifier; password is ignored."""
        from brave.notes.config import settings
        try:
            private = SigningKey.from_string(unhexlify(settings['api']['private']), curve=NIST256p, hashfunc=sha256)
            public = VerifyingKey.from_string(unhexlify(settings['api']['public']), curve=NIST256p, hashfunc=sha256)
        except:
            return "Invalid keys"

        api = API(settings['api']['endpoint'], settings['api']['identity'], private, public)
        result = api.core.info(identifier)
        
        user = self.objects(character__id=result.character.id).first()
        
        if not user:
            user = self(token=identifier, expires=result.expires, seen=datetime.utcnow())
            user.character.id = result.character.id
            user.character.name = result.character.name
            user.corporation.id = result.corporation.id
            user.corporation.name = result.corporation.name
            
            if result.alliance:
                user.alliance.id = result.alliance.id
                user.alliance.name = result.alliance.name
            
            user.save()
        
        else:
            # TODO: Also update the corporate details, if appropriate.
            user.update(set__token=identifier, set__seen=datetime.utcnow())
        
        from brave.notes.core.session import session
        session.user = user
        session.signedin = 1
        
        return user.id, user
开发者ID:BraveNewbies,项目名称:notes,代码行数:38,代码来源:model.py

示例14: config

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import from_string [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: _get_pubkey

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import from_string [as 别名]
 def _get_pubkey(cls, private_key):
     sk = SigningKey.from_string(private_key, curve=SECP256k1, hashfunc=hashlib.sha256)
     vk = sk.get_verifying_key().to_string()  # Uncompressed key
     vk = chr((ord(vk[63]) & 1) + 2) + vk[0:32]  # To compressed key
     return vk
开发者ID:anaoum,项目名称:trezor-emu,代码行数:7,代码来源:bip32.py


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