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


Python ecdsa.SigningKey方法代码示例

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


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

示例1: prepare_key

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import SigningKey [as 别名]
def prepare_key(self, key):

        if isinstance(key, ecdsa.SigningKey) or \
           isinstance(key, ecdsa.VerifyingKey):
            return key

        if isinstance(key, string_types):
            if isinstance(key, text_type):
                key = key.encode('utf-8')

            # Attempt to load key. We don't know if it's
            # a Signing Key or a Verifying Key, so we try
            # the Verifying Key first.
            try:
                key = ecdsa.VerifyingKey.from_pem(key)
            except ecdsa.der.UnexpectedDER:
                key = ecdsa.SigningKey.from_pem(key)

        else:
            raise TypeError('Expecting a PEM-formatted key.')

        return key 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:24,代码来源:py_ecdsa.py

示例2: from_file

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import SigningKey [as 别名]
def from_file(cls, file_path, password=None, encoding='utf-8'):
		"""
		Load the signing key from the specified file. If *password* is
		specified, the file is assumed to have been encrypted using OpenSSL
		with ``aes-256-cbc`` as the cipher and ``sha256`` as the message
		digest. This uses :py:func:`.openssl_decrypt_data` internally for
		decrypting the data.

		:param str file_path: The path to the file to load.
		:param str password: An optional password to use for decrypting the file.
		:param str encoding: The encoding of the data.
		:return: A tuple of the key's ID, and the new :py:class:`.SigningKey` instance.
		:rtype: tuple
		"""
		with open(file_path, 'rb') as file_h:
			file_data = file_h.read()
		if password:
			file_data = openssl_decrypt_data(file_data, password, encoding=encoding)

		file_data = file_data.decode(encoding)
		file_data = serializers.JSON.loads(file_data)
		utilities.validate_json_schema(file_data, 'king-phisher.security.key')
		return cls.from_dict(file_data['signing-key'], encoding=file_data.pop('encoding', 'base64'), id=file_data['id']) 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:25,代码来源:security_keys.py

示例3: test_generation

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import SigningKey [as 别名]
def test_generation(self):
        entity = Entity()

        self.assertEqual(32, len(entity.private_key_bytes))

        # check the other binary representations
        self.assertEqual(base64.b64encode(entity.private_key_bytes).decode(), entity.private_key)
        self.assertEqual(entity.private_key_bytes.hex(), entity.private_key_hex)

        signing_key = ecdsa.SigningKey.from_string(entity.private_key_bytes, curve=Entity.curve,
                                                   hashfunc=Entity.hash_function)
        verifying_key = signing_key.get_verifying_key()

        self.assertEqual(verifying_key.to_string(), entity.public_key_bytes)

        # check the other binary representations
        self.assertEqual(base64.b64encode(entity.public_key_bytes).decode(), entity.public_key)
        self.assertEqual(entity.public_key_bytes.hex(), entity.public_key_hex) 
开发者ID:fetchai,项目名称:ledger-api-py,代码行数:20,代码来源:test_entity.py

示例4: get_pubkeys_from_secret

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import SigningKey [as 别名]
def get_pubkeys_from_secret(secret):
    # public key
    private_key = ecdsa.SigningKey.from_string(secret, curve=SECP256k1)
    public_key = private_key.get_verifying_key()
    K = public_key.to_string()
    K_compressed = GetPubKey(public_key.pubkey, True)
    return K, K_compressed


# Child private key derivation function (from master private key)
# k = master private key (32 bytes)
# c = master chain code (extra entropy for key derivation) (32 bytes)
# n = the index of the key we want to derive. (only 32 bits will be used)
# If n is negative (i.e. the 32nd bit is set), the resulting private key's
#  corresponding public key can NOT be determined without the master private key.
# However, if n is positive, the resulting private key's corresponding
#  public key can be determined without the master private key. 
开发者ID:UlordChain,项目名称:Uwallet,代码行数:19,代码来源:ulord.py

示例5: _process_jwk

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import SigningKey [as 别名]
def _process_jwk(self, jwk_dict):
        if not jwk_dict.get('kty') == 'EC':
            raise JWKError("Incorrect key type. Expected: 'EC', Received: %s" % jwk_dict.get('kty'))

        if not all(k in jwk_dict for k in ['x', 'y', 'crv']):
            raise JWKError('Mandatory parameters are missing')

        if 'd' in jwk_dict:
            # We are dealing with a private key; the secret exponent is enough
            # to create an ecdsa key.
            d = base64_to_long(jwk_dict.get('d'))
            return ecdsa.keys.SigningKey.from_secret_exponent(d, self.curve)
        else:
            x = base64_to_long(jwk_dict.get('x'))
            y = base64_to_long(jwk_dict.get('y'))

            if not ecdsa.ecdsa.point_is_valid(self.curve.generator, x, y):
                raise JWKError("Point: %s, %s is not a valid point" % (x, y))

            point = ecdsa.ellipticcurve.Point(self.curve.curve, x, y, self.curve.order)
            return ecdsa.keys.VerifyingKey.from_public_point(point, self.curve) 
开发者ID:mpdavis,项目名称:python-jose,代码行数:23,代码来源:ecdsa_backend.py

示例6: import_key

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import SigningKey [as 别名]
def import_key(encoded, passphrase=None):
        # encoded, passphrase=None
        # extern_key, passphrase=None
        # key = Cryptodome.PublicKey.ECC.import_key(*args, **kwargs)
        # return to_ecdsakey(key, _from=Cryptodome.PublicKey.ECC, _to=ecdsa.SigningKey)

        if encoded.startswith('-----'):
            return ecdsa.SigningKey.from_pem(encoded)

        # OpenSSH
        # if encoded.startswith(b('ecdsa-sha2-')):
        #    return _import_openssh(encoded)
        # DER
        if ord(encoded[0]) == 0x30:
            return ecdsa.SigningKey.from_der(encoded)
        raise Exception("Invalid Format") 
开发者ID:tintinweb,项目名称:ecdsa-private-key-recovery,代码行数:18,代码来源:__init__.py

示例7: recover_nonce_reuse

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import SigningKey [as 别名]
def recover_nonce_reuse(self, other):
        sig2 = other.sig  # rename it
        h2 = other.h  # rename it
        # precalculate static values
        z = self.h - h2
        r_inv = inverse_mod(self.sig.r, self.n)
        #
        # try all candidates
        #
        for candidate in (self.sig.s - sig2.s,
                          self.sig.s + sig2.s,
                          -self.sig.s - sig2.s,
                          -self.sig.s + sig2.s):
            k = (z * inverse_mod(candidate, self.n)) % self.n
            d = (((self.sig.s * k - self.h) % self.n) * r_inv) % self.n
            signingkey = SigningKey.from_secret_exponent(d, curve=self.curve)
            if signingkey.get_verifying_key().pubkey.verifies(self.h, self.sig):
                self.signingkey = signingkey
                self.k = k
                self.x = d
                return self
        assert False  # could not recover private key 
开发者ID:tintinweb,项目名称:ecdsa-private-key-recovery,代码行数:24,代码来源:__init__.py

示例8: __init__

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import SigningKey [as 别名]
def __init__(self, *args, **kwargs):
		self.id = kwargs.pop('id', None)
		"""An optional string identifier for this key instance."""
		super(SigningKey, self).__init__(*args, **kwargs) 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:6,代码来源:security_keys.py

示例9: from_secret_exponent

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import SigningKey [as 别名]
def from_secret_exponent(cls, *args, **kwargs):
		id_ = kwargs.pop('id', None)
		instance = super(SigningKey, cls).from_secret_exponent(*args, **kwargs)
		orig_vk = instance.verifying_key
		instance.verifying_key = VerifyingKey.from_public_point(orig_vk.pubkey.point, instance.curve, instance.default_hashfunc, id=id_)
		instance.id = id_
		return instance 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:9,代码来源:security_keys.py

示例10: from_string

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import SigningKey [as 别名]
def from_string(cls, string, **kwargs):
		kwargs = _kwarg_curve(kwargs)
		id_ = kwargs.pop('id', None)
		inst = super(SigningKey, cls).from_string(string, **kwargs)
		inst.id = id_
		inst.verifying_key.id = id_
		return inst 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:9,代码来源:security_keys.py

示例11: from_dict

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import SigningKey [as 别名]
def from_dict(cls, value, encoding='base64', **kwargs):
		"""
		Load the signing key from the specified dict object.

		:param dict value: The dictionary to load the key data from.
		:param str encoding: The encoding of the required 'data' key.
		:param dict kwargs: Additional key word arguments to pass to the class on initialization.
		:return: The new signing key.
		:rtype: :py:class:`.SigningKey`
		"""
		return _key_cls_from_dict(cls, value, encoding=encoding, **kwargs) 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:13,代码来源:security_keys.py

示例12: sign_number

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import SigningKey [as 别名]
def sign_number(self, number, entropy=None, k=None):
        curve = ecdsa.SECP256k1
        G = curve.generator
        order = G.order()
        r, s = ecdsa.SigningKey.sign_number(self, number, entropy, k)
        if s > order/2:
            s = order - s
        return r, s 
开发者ID:moocowmoo,项目名称:dashman,代码行数:10,代码来源:dashutil.py

示例13: test_signing_key

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import SigningKey [as 别名]
def test_signing_key(self):
        entity = Entity()
        self.assertIsInstance(entity.signing_key, ecdsa.SigningKey) 
开发者ID:fetchai,项目名称:ledger-api-py,代码行数:5,代码来源:test_entity.py

示例14: sign_number

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import SigningKey [as 别名]
def sign_number(self, number, entropy=None, k=None):
        curve = SECP256k1
        G = curve.generator
        order = G.order()
        r, s = ecdsa.SigningKey.sign_number(self, number, entropy, k)
        if s > order / 2:
            s = order - s
        return r, s 
开发者ID:UlordChain,项目名称:Uwallet,代码行数:10,代码来源:ulord.py

示例15: __init__

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import SigningKey [as 别名]
def __init__(self, key, algorithm):
        if algorithm not in ALGORITHMS.EC:
            raise JWKError('hash_alg: %s is not a valid hash algorithm' % algorithm)

        self.hash_alg = {
            ALGORITHMS.ES256: self.SHA256,
            ALGORITHMS.ES384: self.SHA384,
            ALGORITHMS.ES512: self.SHA512
        }.get(algorithm)
        self._algorithm = algorithm

        self.curve = self.CURVE_MAP.get(self.hash_alg)

        if isinstance(key, (ecdsa.SigningKey, ecdsa.VerifyingKey)):
            self.prepared_key = key
            return

        if isinstance(key, dict):
            self.prepared_key = self._process_jwk(key)
            return

        if isinstance(key, six.string_types):
            key = key.encode('utf-8')

        if isinstance(key, six.binary_type):
            # Attempt to load key. We don't know if it's
            # a Signing Key or a Verifying Key, so we try
            # the Verifying Key first.
            try:
                key = ecdsa.VerifyingKey.from_pem(key)
            except ecdsa.der.UnexpectedDER:
                key = ecdsa.SigningKey.from_pem(key)
            except Exception as e:
                raise JWKError(e)

            self.prepared_key = key
            return

        raise JWKError('Unable to parse an ECKey from key: %s' % key) 
开发者ID:mpdavis,项目名称:python-jose,代码行数:41,代码来源:ecdsa_backend.py


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