本文整理汇总了Python中ecdsa.SigningKey.from_secret_exponent方法的典型用法代码示例。如果您正苦于以下问题:Python SigningKey.from_secret_exponent方法的具体用法?Python SigningKey.from_secret_exponent怎么用?Python SigningKey.from_secret_exponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ecdsa.SigningKey
的用法示例。
在下文中一共展示了SigningKey.from_secret_exponent方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: recover_key
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_secret_exponent [as 别名]
def recover_key(c1,sig1,c2,sig2,pubkey):
#using the same variable names as in:
#http://en.wikipedia.org/wiki/Elliptic_Curve_DSA
curve_order = pubkey.curve.order
n = curve_order
s1 = int(sig1[96:],16)
print("s1: " + str(s1))
s2 = int(sig2[96:],16)
print("s2: " + str(s2))
r = int(sig1[:-96], 16)
print("r: " + str(r))
print("R values match: " + str(int(sig2[:-96],16) == r))
z1 = string_to_number(sha256(c1))
z2 = string_to_number(sha256(c2))
#magical math stuff
sdiff_inv = inverse_mod(((s1-s2)%n),n)
k = ( ((z1-z2)%n) * sdiff_inv) % n
r_inv = inverse_mod(r,n)
da = (((((s1*k) %n) -z1) %n) * r_inv) % n
print("Recovered Da: " + hex(da))
#turn the private key into a signing key
recovered_private_key_ec = SigningKey.from_secret_exponent(da, curve=NIST384p)
return recovered_private_key_ec
示例2: recover_key
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_secret_exponent [as 别名]
def recover_key(c1,sig1,c2,sig2,pubkey):
#using the same variable names as in:
#http://en.wikipedia.org/wiki/Elliptic_Curve_DSA
curve_order = pubkey.curve.order
n = curve_order
s1 = string_to_number(sig1[-48:])
print "s1: " + str(s1)
s2 = string_to_number(sig2[-48:])
print "s2: " + str(s2)
r = string_to_number(sig1[-96:--48])
print "r: " + str(r)
print "R values match: " + str(string_to_number(sig2[-96:--48]) == r)
z1 = string_to_number(sha1(c1))
z2 = string_to_number(sha1(c2))
sdiff_inv = inverse_mod(((s1-s2)%n),n)
k = ( ((z1-z2)%n) * sdiff_inv) % n
r_inv = inverse_mod(r,n)
da = (((((s1*k) %n) -z1) %n) * r_inv) % n
print "Recovered Da: " + hex(da)
recovered_private_key_ec = SigningKey.from_secret_exponent(da, curve=NIST384p)
return recovered_private_key_ec.to_pem()
示例3: get_root_key
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_secret_exponent [as 别名]
def get_root_key(seed):
""" Gets the root key from the seed. """
# :TODO: add support for more than key #0
# see https://github.com/ripple/ripple-lib/blob/develop/src/js/ripple/seed.js
def generate_key(seed):
i = 0
res = 0
while True:
res = from_bytes(hashes.sha512half(seed + to_bytes(i, 4)))
i += 1
if curves.SECP256k1.order >= res:
break
return res
private_generator = generate_key(seed)
public_generator = curves.SECP256k1.generator * private_generator
# use public + private generators to generate a secret
sequence = 0 #
public_compressed = _get_compressed_point(public_generator)
secret = generate_key(public_compressed + to_bytes(sequence, 4))
secret += private_generator
secret %= curves.SECP256k1.order
# use secret to generate a secp256k1 key
return SigningKey.from_secret_exponent(secret, curves.SECP256k1)
示例4: __init__
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_secret_exponent [as 别名]
def __init__(self, secret_exponent, network=BitcoinMainNet,
*args, **kwargs):
if not isinstance(secret_exponent, six.integer_types):
raise ValueError("secret_exponent must be a long")
super(PrivateKey, self).__init__(network=network, *args, **kwargs)
self._private_key = SigningKey.from_secret_exponent(
secret_exponent, curve=SECP256k1)
示例5: create_material
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_secret_exponent [as 别名]
def create_material(self, bits, d=None, x=None, y=None):
curve = self.curve_for_bits(bits)
if d:
return SigningKey.from_secret_exponent(d, curve)
if x and y:
point = ec.Point(curve.curve, x, y, curve.order)
return VerifyingKey.from_public_point(point, curve)
示例6: root_key_from_seed
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_secret_exponent [as 别名]
def root_key_from_seed(secret):
"""This derives your master key the given seed.
Implemented in ripple-lib as ``Seed.prototype.get_key``, and further
is described here:
https://ripple.com/wiki/Account_Family#Root_Key_.28GenerateRootDeterministicKey.29
"""
key = SigningKey.from_secret_exponent(secret, curves.SECP256k1)
return key
示例7: Addr
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_secret_exponent [as 别名]
def Addr(key):
if key == 0:
key = rankey()
print WIF(key)
private_key = SigningKey.from_secret_exponent(int(key,16),curves.SECP256k1)
public_key = sha256(('04'+(private_key.get_verifying_key().to_string()).encode('hex')).decode('hex')).hexdigest()
RIPEMD = new('ripemd160',(public_key).decode('hex')).hexdigest()
dbhash = sha256((sha256(('00'+RIPEMD).decode('hex')).hexdigest()).decode('hex')).hexdigest()
o = '00'+RIPEMD+dbhash[:8]
address = EncodeB58(o)
return address
示例8: generate_pub_key
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_secret_exponent [as 别名]
def generate_pub_key(_pk):
# convert_pk = SigningKey.from_string(_pk, curve=NIST256p)
_pk_unhex = binascii.unhexlify(_pk)
secexp = string_to_number(_pk_unhex)
origin_pk = SigningKey.from_secret_exponent(secexp, curve=NIST256p)
vk = origin_pk.get_verifying_key()
vk_string = vk.to_string()
pub_key = binascii.hexlify(vk_string)
return pub_key, vk
示例9: root_key_from_seed
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_secret_exponent [as 别名]
def root_key_from_seed(seed):
"""This derives your master key the given seed.
Implemented in ripple-lib as ``Seed.prototype.get_key``, and further
is described here:
https://ripple.com/wiki/Account_Family#Root_Key_.28GenerateRootDeterministicKey.29
"""
seq = 0
while True:
private_gen = from_bytes(first_half_of_sha512(
b''.join([seed, to_bytes(seq, 4)])))
seq += 1
if curves.SECP256k1.order >= private_gen:
break
public_gen = curves.SECP256k1.generator * private_gen
# Now that we have the private and public generators, we apparently
# have to calculate a secret from them that can be used as a ECDSA
# signing key.
secret = i = 0
public_gen_compressed = ecc_point_to_bytes_compressed(public_gen)
while True:
secret = from_bytes(first_half_of_sha512(
b"".join([
public_gen_compressed, to_bytes(0, 4), to_bytes(i, 4)])))
i += 1
if curves.SECP256k1.order >= secret:
break
secret = (secret + private_gen) % curves.SECP256k1.order
# The ECDSA signing key object will, given this secret, then expose
# the actual private and public key we are supposed to work with.
key = SigningKey.from_secret_exponent(secret, curves.SECP256k1)
# Attach the generators as supplemental data
key.private_gen = private_gen
key.public_gen = public_gen
return key
示例10: generate
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_secret_exponent [as 别名]
def generate(currency='btc', secret=None, compressed=False):
"""Generate address pair for currency. (Default: BTC)
:currency: string, 3 letter currency code
:secret: string, seed for private address
:compressed: bool, if key pair is on compresses format or not
:returns: tuple, (private_key, public_key) containing representation in hex and base58 format.
"""
from ecdsa import SigningKey, SECP256k1
if secret:
h = hashlib.sha256(secret).hexdigest()
secret_exp = int(h, 16)
sk = SigningKey.from_secret_exponent(secret_exp, curve=SECP256k1)
else:
sk = SigningKey.generate(curve=SECP256k1)
priv = sk.to_string()
pub = sk.get_verifying_key()
if compressed:
priv = priv + '\x01'
if pub.pubkey.point.y() % 2:
prefix = '\x03'
else:
prefix = '\x02'
pub = prefix + pub.to_string()[0:32]
else:
pub = '\x04' + pub.to_string()
priv_hex = priv.encode('hex')
priv_b58 = from_hash160(priv_hex, typ='priv', currency=currency)
pub_hex = sha256hash160(pub).encode('hex')
pub_b58 = from_hash160(pub_hex, currency=currency)
return Key(hex=priv_hex, b58=priv_b58), Key(hex=pub_hex, b58=pub_b58)
示例11: from_exponent
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_secret_exponent [as 别名]
def from_exponent(cls, exponent):
key = SigningKey.from_secret_exponent(exponent, curve=SECP256k1)
return cls(key)
示例12:
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_secret_exponent [as 别名]
from ecdsa import numbertheory, util
from ecdsa import VerifyingKey, SigningKey
PUBLIC_KEY = """
-----BEGIN PUBLIC KEY-----
MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEgTxPtDMGS8oOT3h6fLvYyUGq/BWeKiCB
sQPyD0+2vybIT/Xdl6hOqQd74zr4U2dkj+2q6+vwQ4DCB1X7HsFZ5JczfkO7HCdY
I7sGDvd9eUias/xPdSIL3gMbs26b0Ww0
-----END PUBLIC KEY-----
"""
vk = VerifyingKey.from_pem(PUBLIC_KEY.strip())
msg1 = 'help'
sig1 = binascii.unhexlify('c0e1fc4e3858ac6334cc8798fdec40790d7ad361ffc691c26f2902c41f2b7c2fd1ca916de687858953a6405423fe156cfd7287caf75247c9a32e52ab8260e7ff1e46e55594aea88731bee163035f9ee31f2c2965ac7b2cdfca6100d10ba23826')
msg2 = 'time'
sig2 = binascii.unhexlify('c0e1fc4e3858ac6334cc8798fdec40790d7ad361ffc691c26f2902c41f2b7c2fd1ca916de687858953a6405423fe156c0cbebcec222f83dc9dd5b0d4d8e698a08ddecb79e6c3b35fc2caaa4543d58a45603639647364983301565728b504015d')
r = util.string_to_number(sig1[:48])
s1 = util.string_to_number(sig1[48:])
z1 = util.string_to_number(hashlib.sha256(msg1).digest())
s2 = util.string_to_number(sig2[48:])
z2 = util.string_to_number(hashlib.sha256(msg2).digest())
k = (z1 - z2) * numbertheory.inverse_mod(s1 - s2, vk.pubkey.order) % vk.pubkey.order
d = (s1 * k - z1) * numbertheory.inverse_mod(r, vk.pubkey.order) % vk.pubkey.order
sk = SigningKey.from_secret_exponent(d, curve=vk.curve, hashfunc=hashlib.sha256)
msg3 = 'read %s' % sys.argv[1]
print '%s:%s' % (msg3, binascii.hexlify(sk.sign(msg3, k=k)))
示例13: private_to_address
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_secret_exponent [as 别名]
def private_to_address(private):
private_int = int(b2a_hex(private), 16)
sk = SigningKey.from_secret_exponent(private_int, curves.SECP256k1)
vk = sk.get_verifying_key()
return public_to_address(vk.to_string())