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


Python SigningKey.from_secret_exponent方法代码示例

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


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

示例1: _get_master_private_key

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import from_secret_exponent [as 别名]
 def _get_master_private_key(self):
     return SigningKey.from_secret_exponent(self._secexp(), SECP256k1)
开发者ID:runn1ng,项目名称:trezor-emu,代码行数:4,代码来源:bip32.py

示例2: get_address

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import from_secret_exponent [as 别名]
 def get_address(self, n, address_type):
     secexp = string_to_number(self.get_private_key(n))
     pubkey = SigningKey.from_secret_exponent(secexp, SECP256k1).get_verifying_key()
     address = public_key_to_bc_address('\x04' + pubkey.to_string(), address_type)
     return address
开发者ID:runn1ng,项目名称:trezor-emu,代码行数:7,代码来源:bip32.py

示例3: test_ecdh_check

# 需要导入模块: from ecdsa.keys import SigningKey [as 别名]
# 或者: from ecdsa.keys.SigningKey import from_secret_exponent [as 别名]
    def test_ecdh_check(self):
        '''
https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-23#appendix-C
        '''

        v_stc_material = {
            "kty": "EC",
            "crv": "P-256",
            "x": "gI0GAILBdu7T53akrFmMyGcsF3n5dO7MmwNBHKW5SV0",
            "y": "SLW_xSffzlPWrHEVI30DHM_4egVwt3NQqeUD7nMFpps",
            "d": "0_NxaRPUMQoAJt50Gz8YiTr8gRTwyEaCumd-MToTmIo"
        }

        u_epk_material = {
            "kty": "EC",
            "crv": "P-256",
            "x": "weNJy2HscCSM6AEDTDg04biOvhFhyyWvOHQfeF_PxMQ",
            "y": "e8lnCO-AlStT-NJVX-crhB7QRYhiix03illJOVAOyck",
            "d": "VEmDZpDXXK8p8N0Cndsxs924q6nS1RXFASRl6BfUqdw"
        }

        import re

        def _to_pub(km):
            return (
                int(re.search(r"P-(\d+)$", km['crv']).group(1)),
                (base64.long_from_b64(km['x']),
                 base64.long_from_b64(km['y'])),
            )

        def _to_pri(km):
            return (
                int(re.search(r"P-(\d+)$", km['crv']).group(1)),
                base64.long_from_b64(km['d']),
            )

        pub_tuple = _to_pub(v_stc_material)
        pri_tuple = _to_pri(v_stc_material)

        import pydoc
        curve = pydoc.locate('ecdsa.curves.NIST{0}p'.format(pub_tuple[0]))

        from ecdsa import (
            SigningKey, VerifyingKey,
            ellipticcurve as ec)

        x, y = pub_tuple[1]
        v_pub = VerifyingKey.from_public_point(
            ec.Point(curve.curve, x, y, curve.order),
            curve,
        )

        v_stc = SigningKey.from_secret_exponent(pri_tuple[1], curve)

        # Party U provides a ephemeral key
        pub_tuple = _to_pub(u_epk_material)
        pri_tuple = _to_pri(u_epk_material)

        x, y = pub_tuple[1]
        u_epk = SigningKey.from_secret_exponent(pri_tuple[1], curve)

        from jose.jwa.ec import ecdsa_dhZ

        # Party U compute
        shared_secret_u = ecdsa_dhZ(v_pub, u_epk)

        print("Aggreement:", base64.long_to_b64(shared_secret_u))

        from Crypto.Util.number import long_to_bytes
        from math import ceil

        block_size = int(ceil(pub_tuple[0] / 8.0))
        # bit number(512 )  / 8 -> octets

        Zu = long_to_bytes(shared_secret_u, block_size)

        Z_jwa = [158, 86, 217, 29, 129, 113, 53,
                 211, 114, 131, 66, 131, 191, 132,
                 38, 156, 251, 49, 110, 163, 218,
                 128, 106, 72, 246, 218, 167, 121,
                 140, 254, 144, 196]

        self.assertEqual(_ilist(Zu), Z_jwa)

        # Other Information used in Concat KDF
        # AlgorithmID || PartyUInfo || PartyVInfo || SuppPubInfo
        from struct import pack

        def _otherInfo(alg, pu, pv, klen):
            return b('').join([
                pack("!I", len(alg)),
                alg,
                pack("!I", len(pu)),
                pu,
                pack("!I", len(pv)),
                pv,
                pack("!I", klen),
            ])

        oi_u = _otherInfo(
#.........这里部分代码省略.........
开发者ID:hdknr,项目名称:jose,代码行数:103,代码来源:test_ec.py


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