本文整理汇总了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)
示例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
示例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(
#.........这里部分代码省略.........