本文整理汇总了Python中ecdsa.keys.SigningKey类的典型用法代码示例。如果您正苦于以下问题:Python SigningKey类的具体用法?Python SigningKey怎么用?Python SigningKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SigningKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dhZ
def test_dhZ(self):
from ecdsa.keys import SigningKey # VerifyingKey
from ecdsa.curves import NIST521p
# Party V(recepient) declares a satic key pair
curve = NIST521p
v_stc = SigningKey.generate(curve=curve)
# and advertise to Party U(Sender) ( U <--(pub key)-- V)
v_pub = v_stc.get_verifying_key()
self.assertEqual(v_pub.curve, curve)
print(v_pub.curve)
# Party U provides a ephemeral key
u_epk = SigningKey.generate(curve=v_pub.curve)
from jose.jwa import ec
# Compute ECDH as shared secret
# This shared secret itself is NOT have to be exchanged.
shared_secret_u = ec.ecdsa_dhZ(v_pub, u_epk)
# Party V recive Epemeral Public Key ( U --(pub key)--> V)
v_epk = u_epk.get_verifying_key()
# Party V compute
shared_secret_v = ec.ecdsa_dhZ(v_epk, v_stc)
# Secrete Agreeed!
self.assertEqual(shared_secret_u, shared_secret_v)
示例2: setUp
def setUp(self):
self.private_key = SigningKey.generate()
self.public_keys = tuple(PublicKey.from_signing_key(SigningKey.generate()) for _ in range(2))
self.operation = Operation(OperationRev(), 'http://example.com', self.public_keys)
sign_object(PublicKey.from_signing_key(self.private_key), self.private_key, self.operation)
self.uuid = self.operation.uuid
self.identifier = Identifier.from_operation(self.operation)
示例3: setUp
def setUp(self):
initialise_database('test_database_file')
self.private_keys = [SigningKey.generate(), SigningKey.generate()]
self.public_keys = [PublicKey.from_signing_key(private_key) for private_key in self.private_keys]
self.operation = [
Operation(OperationRev(), 'http://example.com/', [self.public_keys[1]]),
Operation(OperationRev(), 'http://example2.com/', [self.public_keys[0], self.public_keys[1]]),
Operation(OperationRev(), 'http://example3.com/', [self.public_keys[1]])
]
示例4: test_new_keys
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()))
示例5: test_exchage
def test_exchage(self):
from ecdsa import SigningKey, NIST521p
alice_own = SigningKey.generate(curve=NIST521p)
bob_own = SigningKey.generate(curve=NIST521p)
alice_pri = alice_own.privkey
alice_pub = alice_pri.public_key
bob_pri = bob_own.privkey
bob_pub = bob_pri.public_key
alice_pub_point = alice_pub.point
bob_pub_point = bob_pub.point
print(alice_pub_point, bob_pub_point)
示例6: new_keys
def new_keys(cls, curve=NIST192p): # TODO different curve as default?
"""
Create new user using auto-generated keys.
:param curve: private key's generation curve
"""
return cls(SigningKey.generate(curve=curve))
示例7: setUp
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('GETaddressimo.com/address/0123456789abcdef/sfthis is some crazy random data, dude! you know you gotta love this!', 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.mockRequest.method = 'GET'
self.mockRequest.path = '/address/0123456789abcdef/sf'
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)
示例8: test_no_database
def test_no_database(self):
with self.assertRaisesRegex(pmpi.database.Database.InitialisationError, "initialise database first"):
Block.get_ids_list()
with self.assertRaisesRegex(pmpi.database.Database.InitialisationError, "initialise database first"):
Block.get(sha256(b'something').digest())
private_key = SigningKey.generate()
public_key = PublicKey.from_signing_key(private_key)
operations = [
Operation(OperationRev(), 'http://example0.com/', [public_key]),
Operation(OperationRev(), 'http://example1.com/', [public_key])
]
for op in operations:
sign_object(public_key, private_key, op)
block = Block.from_operations_list(BlockRev(), int(time.time()), operations)
block.mine()
sign_object(public_key, private_key, block)
with self.assertRaisesRegex(pmpi.database.Database.InitialisationError, "initialise database first"):
block.put()
with self.assertRaisesRegex(pmpi.database.Database.InitialisationError, "initialise database first"):
block.remove()
示例9: get
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()
)
示例10: test_generate
def test_generate(self):
def hexdigest(digester, data):
import hashlib
return hashlib.new(digester, data).hexdigest()
def longdigest(digester, data):
return int(hexdigest(digester, data), 16)
from ecdsa.keys import SigningKey, VerifyingKey
from ecdsa.curves import NIST521p
pri = SigningKey.generate(curve=NIST521p)
pub = pri.get_verifying_key()
self.assertTrue(isinstance(pub, VerifyingKey))
data = 'what a wonderfull world.'
digest = longdigest('sha256', b(data))
sig = pri.sign_number(digest)
self.assertTrue(isinstance(sig, tuple))
self.assertEqual(len(sig), 2)
from ecdsa.ecdsa import Signature
sigobj = Signature(*sig) # (r, s)
self.assertTrue(pub.pubkey.verifies(digest, sigobj))
示例11: __init__
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__()
示例12: setUp
def setUp(self):
self.private_key = SigningKey.generate()
self.public_key = PublicKey.from_signing_key(self.private_key)
self.operations = [Operation(
OperationRev(), 'http://example.com/', [self.public_key]) for _ in range(Block.MIN_OPERATIONS + 1)]
for op in self.operations:
sign_object(self.public_key, self.private_key, op)
示例13: _get_brave_api
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))
示例14: generate_key
def generate_key(identifier):
from brave.core.application.model import Application
key = SigningKey.generate(NIST256p, hashfunc=sha256)
Application.objects(
id = identifier,
key__private = None # Make sure we don't override an existing one.
).update(
set__key__private = hexlify(key.to_string())
)
示例15: authorized
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)