本文整理汇总了Python中ecdsa.SigningKey.generate方法的典型用法代码示例。如果您正苦于以下问题:Python SigningKey.generate方法的具体用法?Python SigningKey.generate怎么用?Python SigningKey.generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ecdsa.SigningKey
的用法示例。
在下文中一共展示了SigningKey.generate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import generate [as 别名]
def test():
priv = SigningKey.generate(curve=NIST384p)
pub = priv.get_verifying_key()
print "Private key generated:"
generatedKey = priv.to_pem()
print generatedKey
txt1 = "Dedication"
txt2 = "Do you have it?"
#K chosen by a fair roll of a 1d10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
sig1 = priv.sign(txt1, k=4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444)
print "Signature 1: " + str(sig1.encode('hex'))
sig2 = priv.sign(txt2, k=4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444)
print "Signature 2: " + str(sig2.encode('hex'))
print "Signature 1 verification: " + str(pub.verify(sig1, txt1))
print "Signature 2 verification: " + str(pub.verify(sig2, txt2))
key = recover_key(txt1, sig1, txt2, sig2, pub)
print "Private key recovered:"
print key
print "Equality of generated & recovered keys: " + str(generatedKey == key)
示例2: build_vectors
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import generate [as 别名]
def build_vectors(fips_vectors):
vectors = defaultdict(list)
for vector in fips_vectors:
vectors[vector['digest_algorithm']].append(vector['message'])
for digest_algorithm, messages in vectors.items():
if digest_algorithm not in HASHLIB_HASH_TYPES:
continue
yield ""
yield "[K-256,{0}]".format(digest_algorithm)
yield ""
for message in messages:
# Make a hash context
hash_func = TruncatedHash(HASHLIB_HASH_TYPES[digest_algorithm]())
# Sign the message using warner/ecdsa
secret_key = SigningKey.generate(curve=SECP256k1)
public_key = secret_key.get_verifying_key()
signature = secret_key.sign(message, hashfunc=hash_func,
sigencode=sigencode_der)
r, s = sigdecode_der(signature, None)
yield "Msg = {0}".format(hexlify(message))
yield "d = {0:x}".format(secret_key.privkey.secret_multiplier)
yield "Qx = {0:x}".format(public_key.pubkey.point.x())
yield "Qy = {0:x}".format(public_key.pubkey.point.y())
yield "R = {0:x}".format(r)
yield "S = {0:x}".format(s)
yield ""
示例3: gen_key
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import generate [as 别名]
def gen_key(self, filename):
"""
Generate a new Signing key using NIST P-256 curve
"""
self.sk = SigningKey.generate(curve=NIST256p)
with open(filename, "w") as sk_file:
sk_file.write(self.sk.to_pem())
示例4: generate_pri_key
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import generate [as 别名]
def generate_pri_key():
seed = get_seed()
rng1 = PRNG(seed)
sk = SigningKey.generate(entropy=rng1, curve=NIST256p)
sk_string = sk.to_string()
sk_string_hex = binascii.hexlify(sk_string)
return sk_string_hex, sk
示例5: generate
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import generate [as 别名]
def generate(curve):
if curve not in _policy_.keys():
return False
sk = SigningKey.generate(curve=_policy_[curve][0])
vk = sk.get_verifying_key()
pubKey = vk.to_der()
prvKey = sk.to_der()
return (pubKey, prvKey)
示例6: setUpClass
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import generate [as 别名]
def setUpClass(cls):
log.info('Generating ECDSA Keypairs for Testing')
cls.sender_sk = SigningKey.generate(curve=curves.SECP256k1)
cls.receiver_sk = SigningKey.generate(curve=curves.SECP256k1)
log.info('Setup IdObj for testid')
cls.test_id_obj = IdObject()
cls.test_id_obj.auth_public_key = cls.receiver_sk.get_verifying_key().to_der().encode('hex')
cls.test_id_obj.id = 'testid'
cls.test_id_obj.paymentprotocol_only = True
cls.resolver = PluginManager.get_plugin('RESOLVER', config.resolver_type)
cls.resolver.save(cls.test_id_obj)
log.info('Save testid IdObj')
log.info('Setup Class Identifier')
cls.identifier = None
示例7: __init__
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import generate [as 别名]
def __init__(self):
self.privatekey = SigningKey.generate()
self.publickey = self.privatekey.get_verifying_key()
self.blockhead = None
self.maxnumtrans = 1000
self.database = [[0] * 2 for i in range(self.maxnumtrans)]
self.top = 0
self.currentblock = block.block(None)
self.blockhead = Treenode()
self.genesis = Treenode() # height will be zero for genesis block
self.leafhead = self.genesis # head of the list of leaves, points to an empty node initially
示例8: generate
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import generate [as 别名]
def generate(curve=curves.NIST256p, progress_func=None):
"""
Generate a new private ECDSA key. This factory function can be used to
generate a new host key or authentication key.
:param function progress_func: Not used for this type of key.
:returns: A new private key (`.ECDSAKey`) object
"""
signing_key = SigningKey.generate(curve)
key = ECDSAKey(vals=(signing_key, signing_key.get_verifying_key()))
return key
示例9: generate_new_key_pair
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import generate [as 别名]
def generate_new_key_pair():
# Private key
signing_key = SigningKey.generate(
curve=SECP256k1,
hashfunc=sha256,
)
# Public key
verifying_key = signing_key.get_verifying_key()
return signing_key, verifying_key
示例10: generate
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import generate [as 别名]
def generate(curve=curves.NIST256p, progress_func=None):
"""
Generate a new private RSA key. This factory function can be used to
generate a new host key or authentication key.
:param function progress_func:
an optional function to call at key points in key generation (used
by ``pyCrypto.PublicKey``).
:returns: A new private key (`.RSAKey`) object
"""
signing_key = SigningKey.generate(curve)
key = ECDSAKey(vals=(signing_key, signing_key.get_verifying_key()))
return key
示例11: __init__
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import generate [as 别名]
def __init__(self, key=None):
self.secretKey = self.verifKey = None
# Recuperation
if key is not None:
self.secretKey = SigningKey.from_string(key, curve=NIST384p)
# Auto-generation
else:
self.secretKey = SigningKey.generate(curve=NIST384p)
self.verifKey = self.secretKey.get_verifying_key()
示例12: generate_key
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import generate [as 别名]
def generate_key(self):
"""
create keypair, program_id and jid
"""
signingkey = SigningKey.generate(curve=NIST256p)
sk_text = "private-jid0-%s" % my_b32encode(signingkey.to_string())
verifyingkey = signingkey.get_verifying_key()
vk_text = "public-jid0-%s" % my_b32encode(verifyingkey.to_string())
self.jid = vk_to_jid(verifyingkey)
self.program_id = jid_to_programid(self.jid)
self.private_key = sk_text
self.public_key = vk_text
示例13: generate_ECC_key
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import generate [as 别名]
def generate_ECC_key(args):
'''
Generate an ECC keypair in PEM format
'''
from ecdsa import SigningKey
curve = getattr(__import__('ecdsa'), args.curve)
private_key = SigningKey.generate(curve=curve)
public_key = private_key.get_verifying_key()
with open('privateEC.pem', 'wb') as key_file:
key_file.write(private_key.to_pem())
with open('publicEC.pem', 'wb') as key_file:
key_file.write(public_key.to_pem())
示例14: generate_key
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import generate [as 别名]
def generate_key(self):
"""
create keypair, program_id and jid
"""
from ecdsa import SigningKey, NIST256p
from cuddlefish.preflight import vk_to_jid, jid_to_programid, my_b32encode
sk = SigningKey.generate(curve=NIST256p)
sk_text = "private-jid0-%s" % my_b32encode(sk.to_string())
vk = sk.get_verifying_key()
vk_text = "public-jid0-%s" % my_b32encode(vk.to_string())
self.jid = vk_to_jid(vk)
self.program_id = jid_to_programid(self.jid)
self.private_key = sk_text
self.public_key = vk_text
示例15: main
# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import generate [as 别名]
def main(args):
message = "Hello, P2PSP!" * 1024
sk = SigningKey.generate()
vk = sk.get_verifying_key()
# measure the sign time
start_time = time.time()
for _ in xrange(N):
sig = sign(message, sk)
print "key.sign x{0} times: {1}s".format(N, time.time() - start_time)
#measure the verify time
sig = sign(message, sk)
start_time = time.time()
for _ in xrange(N):
r = check(message, vk, sig)
print "key.verify x{0} times: {1}s".format(N, time.time() - start_time)