本文整理汇总了Python中cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateNumbers方法的典型用法代码示例。如果您正苦于以下问题:Python ec.EllipticCurvePrivateNumbers方法的具体用法?Python ec.EllipticCurvePrivateNumbers怎么用?Python ec.EllipticCurvePrivateNumbers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cryptography.hazmat.primitives.asymmetric.ec
的用法示例。
在下文中一共展示了ec.EllipticCurvePrivateNumbers方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: hex_to_priv_key
# 需要导入模块: from cryptography.hazmat.primitives.asymmetric import ec [as 别名]
# 或者: from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurvePrivateNumbers [as 别名]
def hex_to_priv_key(priv_key_hex, public_key_hex):
priv_key_value = long(priv_key_hex, 16)
public_key = hex_to_key(public_key_hex)
public_numbers = public_key.public_numbers()
private_numbers = ec.EllipticCurvePrivateNumbers(priv_key_value, public_numbers)
priv_key = private_numbers.private_key(backend)
return priv_key
# Hybrid Encryption Scheme:
# - We perform a Elliptic Curves Diffie-Hellman Key Exchange using:
# - SECP256K1 as curve for key generation
# - ANSI X9.63 KDF as Key Derivation Function to derive the shared secret
# - The symmetric cipher is an AES256.MODE_GCM with authentication tag 16-byte
# of length. Since the key is used only once, we can pick the known nonce/iv
# '000000000000' (96 bits of length). We return concatenation of the encoded
# point, the tag and the ciphertext
示例2: _process_jwk
# 需要导入模块: from cryptography.hazmat.primitives.asymmetric import ec [as 别名]
# 或者: from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurvePrivateNumbers [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')
x = base64_to_long(jwk_dict.get('x'))
y = base64_to_long(jwk_dict.get('y'))
curve = {
'P-256': ec.SECP256R1,
'P-384': ec.SECP384R1,
'P-521': ec.SECP521R1,
}[jwk_dict['crv']]
public = ec.EllipticCurvePublicNumbers(x, y, curve())
if 'd' in jwk_dict:
d = base64_to_long(jwk_dict.get('d'))
private = ec.EllipticCurvePrivateNumbers(d, public)
return private.private_key(self.cryptography_backend())
else:
return public.public_key(self.cryptography_backend())
示例3: _ec_pri
# 需要导入模块: from cryptography.hazmat.primitives.asymmetric import ec [as 别名]
# 或者: from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurvePrivateNumbers [as 别名]
def _ec_pri(self, k, curve):
return ec.EllipticCurvePrivateNumbers(self._decode_int(k['d']),
self._ec_pub(k, curve))
示例4: _fromECComponents
# 需要导入模块: from cryptography.hazmat.primitives.asymmetric import ec [as 别名]
# 或者: from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurvePrivateNumbers [as 别名]
def _fromECComponents(cls, x, y, curve, privateValue=None):
"""
Build a key from EC components.
@param x: The affine x component of the public point used for verifying.
@type x: L{int}
@param y: The affine y component of the public point used for verifying.
@type y: L{int}
@param curve: NIST name of elliptic curve.
@type curve: L{bytes}
@param privateValue: The private value.
@type privateValue: L{int}
"""
publicNumbers = ec.EllipticCurvePublicNumbers(
x=x, y=y, curve=_curveTable[curve])
if privateValue is None:
# We have public components.
keyObject = publicNumbers.public_key(default_backend())
else:
privateNumbers = ec.EllipticCurvePrivateNumbers(
private_value=privateValue, public_numbers=publicNumbers)
keyObject = privateNumbers.private_key(default_backend())
return cls(keyObject)
示例5: __privkey__
# 需要导入模块: from cryptography.hazmat.primitives.asymmetric import ec [as 别名]
# 或者: from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurvePrivateNumbers [as 别名]
def __privkey__(self):
ecp = ec.EllipticCurvePublicNumbers(self.p.x, self.p.y, self.oid.curve())
return ec.EllipticCurvePrivateNumbers(self.s, ecp).private_key(default_backend())
示例6: dummy_generate_key_pair
# 需要导入模块: from cryptography.hazmat.primitives.asymmetric import ec [as 别名]
# 或者: from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurvePrivateNumbers [as 别名]
def dummy_generate_key_pair(obj):
private_key_value = 94761803665136558137557783047955027733968423115106677159790289642479432803037
public_key_numbers = "042bdab212fa8ba1b7c843301682a4db424d307246c7e1e6083c41d9ca7b098bf30b3d63e2ec6278488c135360456cc054b3444ecc45998c08894cbc1370f5f989"
public_key_numbers_obj = ec.EllipticCurvePublicNumbers.from_encoded_point(ec.SECP256R1(), unhexlify(public_key_numbers))
obj.P = ec.EllipticCurvePrivateNumbers(private_value=private_key_value, public_numbers=public_key_numbers_obj).private_key(default_backend())
if obj.transport.server_mode:
obj.Q_S = ec.EllipticCurvePublicNumbers.from_encoded_point(ec.SECP256R1(), unhexlify(public_key_numbers)).public_key(default_backend())
return
obj.Q_C = ec.EllipticCurvePublicNumbers.from_encoded_point(ec.SECP256R1(), unhexlify(public_key_numbers)).public_key(default_backend())
示例7: _run
# 需要导入模块: from cryptography.hazmat.primitives.asymmetric import ec [as 别名]
# 或者: from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurvePrivateNumbers [as 别名]
def _run(self, mode):
if mode == 'encrypt':
func = ece.encrypt
local = 'sender'
inp = 'input'
outp = 'encrypted'
else:
func = ece.decrypt
local = 'receiver'
inp = 'encrypted'
outp = 'input'
for data in self.legacy_data:
logmsg('%s: %s' % (mode, data['test']))
p = data['params'][mode]
if 'pad' in p and mode == 'encrypt':
# This library doesn't pad in exactly the same way.
continue
if 'keys' in data:
key = None
decode_pub = ec.EllipticCurvePublicNumbers.from_encoded_point
pubnum = decode_pub(ec.SECP256R1(),
b64d(data['keys'][local]['public']))
d = 0
dbin = b64d(data['keys'][local]['private'])
for i in range(0, len(dbin), 4):
d = (d << 32) + struct.unpack('!L', dbin[i:i + 4])[0]
privnum = ec.EllipticCurvePrivateNumbers(d, pubnum)
private_key = privnum.private_key(default_backend())
else:
key = b64d(p['key'])
private_key = None
if 'authSecret' in p:
auth_secret = b64d(p['authSecret'])
else:
auth_secret = None
if 'dh' in p:
dh = b64d(p['dh'])
else:
dh = None
result = func(
b64d(data[inp]),
salt=b64d(p['salt']),
key=key,
dh=dh,
auth_secret=auth_secret,
keyid=p.get('keyid'),
private_key=private_key,
rs=p.get('rs', 4096),
version=p['version'],
)
eq_(b64d(data[outp]), result)