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


Python ecdsa.VerifyingKey方法代码示例

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


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

示例1: prepare_key

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import VerifyingKey [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: sign_dict

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import VerifyingKey [as 别名]
def sign_dict(self, data, signature_encoding='base64'):
		"""
		Sign a dictionary object. The dictionary will have a 'signature' key
		added is required by the :py:meth:`.VerifyingKey.verify_dict` method.
		To serialize the dictionary to data suitable for the operation the
		:py:func:`json.dumps` function is used and the resulting data is then
		UTF-8 encoded.

		:param dict data: The dictionary of data to sign.
		:param str signature_encoding: The encoding name of the signature data.
		:return: The dictionary object is returned with the 'signature' key added.
		"""
		utilities.assert_arg_type(data, dict, arg_pos=1)
		data = copy.copy(data)
		data.pop('signature', None)  # remove a pre-existing signature
		json_data = json.dumps(data, sort_keys=True).encode('utf-8')
		data['signature'] = _encoding_data(self.sign(json_data), encoding=signature_encoding)
		return data 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:20,代码来源:security_keys.py

示例3: _load_key_store

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import VerifyingKey [as 别名]
def _load_key_store(self, file_name):
		file_path = find.data_file(file_name)
		if not file_path:
			return 0
		with open(file_path, 'r') as file_h:
			key_store = serializers.JSON.load(file_h)
		utilities.validate_json_schema(key_store, 'king-phisher.security')
		key_store = key_store['keys']
		loaded = 0
		for key_idx, key in enumerate(key_store, 1):
			identifier = key['id']
			if identifier in self.keys:
				self.logger.warning("skipping loading {0}:{1} due to a duplicate id".format(file_name, key_idx))
				continue
			verifying_key = key['verifying-key']
			key['verifying-key'] = VerifyingKey.from_dict(verifying_key, encoding=verifying_key.pop('encoding', 'base64'))
			self.keys[identifier] = key
			self.logger.debug("loaded key id: {0} from: {1}".format(identifier, file_path))
			loaded += 1
		return loaded 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:22,代码来源:security_keys.py

示例4: _process_jwk

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import VerifyingKey [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

示例5: from_secret_exponent

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import VerifyingKey [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

示例6: __init__

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

示例7: from_public_point

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

示例8: from_string

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

示例9: _CKD_pub

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import VerifyingKey [as 别名]
def _CKD_pub(cK, c, s):
    import hmac
    from ecdsa.util import string_to_number, number_to_string
    order = generator_secp256k1.order()
    I = hmac.new(c, cK + s, hashlib.sha512).digest()
    curve = SECP256k1
    pubkey_point = string_to_number(I[0:32])*curve.generator + ser_to_point(cK)
    public_key = ecdsa.VerifyingKey.from_public_point( pubkey_point, curve = SECP256k1 )
    c_n = I[32:]
    cK_n = GetPubKey(public_key.pubkey,True)
    return cK_n, c_n 
开发者ID:mazaclub,项目名称:encompass,代码行数:13,代码来源:bitcoin.py

示例10: __init__

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import VerifyingKey [as 别名]
def __init__(self, public_key):

        if isinstance(public_key, Identity):
            self._verifying_key = public_key.verifying_key
        elif isinstance(public_key, ecdsa.VerifyingKey):
            self._verifying_key = public_key
        elif isinstance(public_key, bytes):
            self._verifying_key = ecdsa.VerifyingKey.from_string(public_key, curve=self.curve,
                                                                 hashfunc=self.hash_function)
        else:
            raise RuntimeError('Failed')

        # cache the binary representations of the public key
        self._public_key_bytes = self._verifying_key.to_string()
        self._public_key = base64.b64encode(self._public_key_bytes).decode() 
开发者ID:fetchai,项目名称:ledger-api-py,代码行数:17,代码来源:identity.py

示例11: _CKD_pub

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import VerifyingKey [as 别名]
def _CKD_pub(cK, c, s):
    order = generator_secp256k1.order()
    I = hmac.new(c, cK + s, hashlib.sha512).digest()
    curve = SECP256k1
    pubkey_point = string_to_number(I[0:32]) * curve.generator + ser_to_point(cK)
    public_key = ecdsa.VerifyingKey.from_public_point(pubkey_point, curve=SECP256k1)
    c_n = I[32:]
    cK_n = GetPubKey(public_key.pubkey, True)
    return cK_n, c_n 
开发者ID:UlordChain,项目名称:Uwallet,代码行数:11,代码来源:ulord.py

示例12: __init__

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import VerifyingKey [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

示例13: is_public

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import VerifyingKey [as 别名]
def is_public(self):
        return isinstance(self.prepared_key, ecdsa.VerifyingKey) 
开发者ID:mpdavis,项目名称:python-jose,代码行数:4,代码来源:ecdsa_backend.py

示例14: __init__

# 需要导入模块: import ecdsa [as 别名]
# 或者: from ecdsa import VerifyingKey [as 别名]
def __init__(self, key, algorithm, cryptography_backend=default_backend):
        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.cryptography_backend = cryptography_backend

        if hasattr(key, 'public_bytes') or hasattr(key, 'private_bytes'):
            self.prepared_key = key
            return

        if None not in (EcdsaSigningKey, EcdsaVerifyingKey) and isinstance(key, (EcdsaSigningKey, EcdsaVerifyingKey)):
            # convert to PEM and let cryptography below load it as PEM
            key = key.to_pem().decode('utf-8')

        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 Public Key or a Private Key, so we try
            # the Public Key first.
            try:
                try:
                    key = load_pem_public_key(key, self.cryptography_backend())
                except ValueError:
                    key = load_pem_private_key(key, password=None, backend=self.cryptography_backend())
            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,代码行数:46,代码来源:cryptography_backend.py


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