本文整理匯總了Python中cryptography.hazmat.primitives.asymmetric.ec.SECP192R1屬性的典型用法代碼示例。如果您正苦於以下問題:Python ec.SECP192R1屬性的具體用法?Python ec.SECP192R1怎麽用?Python ec.SECP192R1使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類cryptography.hazmat.primitives.asymmetric.ec
的用法示例。
在下文中一共展示了ec.SECP192R1屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_ecc_decode_compressed_point_prime_unsupported
# 需要導入模塊: from cryptography.hazmat.primitives.asymmetric import ec [as 別名]
# 或者: from cryptography.hazmat.primitives.asymmetric.ec import SECP192R1 [as 別名]
def test_ecc_decode_compressed_point_prime_unsupported():
with pytest.raises(NotSupportedError) as excinfo:
_ecc_decode_compressed_point(curve=ec.SECP192R1(), compressed_point="\x02skdgaiuhgijudflkjsdgfkjsdflgjhsd")
excinfo.match(r"Curve secp192r1 is not supported at this time")
示例2: test_basic
# 需要導入模塊: from cryptography.hazmat.primitives.asymmetric import ec [as 別名]
# 或者: from cryptography.hazmat.primitives.asymmetric.ec import SECP192R1 [as 別名]
def test_basic(self):
self.assertIsInstance(parse_key_curve(), type(ca_settings.CA_DEFAULT_ECC_CURVE))
self.assertIsInstance(parse_key_curve('SECT409R1'), ec.SECT409R1)
self.assertIsInstance(parse_key_curve('SECP521R1'), ec.SECP521R1)
self.assertIsInstance(parse_key_curve('SECP192R1'), ec.SECP192R1)
示例3: generate_private_key
# 需要導入模塊: from cryptography.hazmat.primitives.asymmetric import ec [as 別名]
# 或者: from cryptography.hazmat.primitives.asymmetric.ec import SECP192R1 [as 別名]
def generate_private_key(key_type):
"""
Generates a new private key based on key_type.
Valid key types: RSA2048, RSA4096', 'ECCPRIME192V1', 'ECCPRIME256V1', 'ECCSECP192R1',
'ECCSECP224R1', 'ECCSECP256R1', 'ECCSECP384R1', 'ECCSECP521R1', 'ECCSECP256K1',
'ECCSECT163K1', 'ECCSECT233K1', 'ECCSECT283K1', 'ECCSECT409K1', 'ECCSECT571K1',
'ECCSECT163R2', 'ECCSECT233R1', 'ECCSECT283R1', 'ECCSECT409R1', 'ECCSECT571R2'
:param key_type:
:return:
"""
_CURVE_TYPES = {
"ECCPRIME192V1": ec.SECP192R1(),
"ECCPRIME256V1": ec.SECP256R1(),
"ECCSECP192R1": ec.SECP192R1(),
"ECCSECP224R1": ec.SECP224R1(),
"ECCSECP256R1": ec.SECP256R1(),
"ECCSECP384R1": ec.SECP384R1(),
"ECCSECP521R1": ec.SECP521R1(),
"ECCSECP256K1": ec.SECP256K1(),
"ECCSECT163K1": ec.SECT163K1(),
"ECCSECT233K1": ec.SECT233K1(),
"ECCSECT283K1": ec.SECT283K1(),
"ECCSECT409K1": ec.SECT409K1(),
"ECCSECT571K1": ec.SECT571K1(),
"ECCSECT163R2": ec.SECT163R2(),
"ECCSECT233R1": ec.SECT233R1(),
"ECCSECT283R1": ec.SECT283R1(),
"ECCSECT409R1": ec.SECT409R1(),
"ECCSECT571R2": ec.SECT571R1(),
}
if key_type not in CERTIFICATE_KEY_TYPES:
raise Exception(
"Invalid key type: {key_type}. Supported key types: {choices}".format(
key_type=key_type, choices=",".join(CERTIFICATE_KEY_TYPES)
)
)
if "RSA" in key_type:
key_size = int(key_type[3:])
return rsa.generate_private_key(
public_exponent=65537, key_size=key_size, backend=default_backend()
)
elif "ECC" in key_type:
return ec.generate_private_key(
curve=_CURVE_TYPES[key_type], backend=default_backend()
)
示例4: test_lib_crypto_ecc_exchange
# 需要導入模塊: from cryptography.hazmat.primitives.asymmetric import ec [as 別名]
# 或者: from cryptography.hazmat.primitives.asymmetric.ec import SECP192R1 [as 別名]
def test_lib_crypto_ecc_exchange(self):
spvk1 = s_ecc.PriKey.generate()
spbk1 = spvk1.public()
spvk2 = s_ecc.PriKey.generate()
spbk2 = spvk2.public()
k1 = (spvk1.exchange(spbk2))
k2 = (spvk2.exchange(spbk1))
self.eq(k1, k2)
# Curves must be the same
_pkd = c_ec.generate_private_key(
c_ec.SECP192R1(), # We don't use this curve
default_backend()
)
prkdiff = s_ecc.PriKey(_pkd)
pbkdiff = prkdiff.public()
self.raises(s_exc.BadEccExchange, spvk1.exchange, pbkdiff)
self.raises(s_exc.BadEccExchange, prkdiff.exchange, spbk1)
# Do a demonstrative ephemeral exchange
epvk1 = s_ecc.PriKey.generate()
epbk1 = epvk1.public()
epvk2 = s_ecc.PriKey.generate()
epbk2 = epvk2.public()
# assume epbk2 is sent to the owner of pvk1
z1e = epvk1.exchange(epbk2)
z1s = spvk1.exchange(spbk2)
z1 = z1e + z1s
# assume epbk1 is sent to the owner of pvk2
z2e = epvk2.exchange(epbk1)
z2s = spvk2.exchange(spbk1)
z2 = z2e + z2s
self.eq(z1, z2)
# run through kdf
kdf1 = c_hkdf.HKDF(c_hashes.SHA256(),
length=64,
salt=None,
info=b'test',
backend=default_backend())
k1 = kdf1.derive(z1)
k1tx, k1rx = k1[32:], k1[:32]
kdf2 = c_hkdf.HKDF(c_hashes.SHA256(),
length=64,
salt=None,
info=b'test',
backend=default_backend())
k2 = kdf2.derive(z2)
k2rx, k2tx = k2[32:], k2[:32]
self.eq(k1tx, k2rx)
self.eq(k1rx, k2tx)
self.ne(k1tx, k2tx)