本文整理匯總了Python中Cryptodome.PublicKey.ECC.construct方法的典型用法代碼示例。如果您正苦於以下問題:Python ECC.construct方法的具體用法?Python ECC.construct怎麽用?Python ECC.construct使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Cryptodome.PublicKey.ECC
的用法示例。
在下文中一共展示了ECC.construct方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_ref_keys
# 需要導入模塊: from Cryptodome.PublicKey import ECC [as 別名]
# 或者: from Cryptodome.PublicKey.ECC import construct [as 別名]
def create_ref_keys():
key_lines = load_file("ecc_p256.txt").splitlines()
private_key_d = bytes_to_long(compact(key_lines[2:5]))
public_key_xy = compact(key_lines[6:11])
assert bord(public_key_xy[0]) == 4 # Uncompressed
public_key_x = bytes_to_long(public_key_xy[1:33])
public_key_y = bytes_to_long(public_key_xy[33:])
return (ECC.construct(curve="P-256", d=private_key_d),
ECC.construct(curve="P-256", point_x=public_key_x, point_y=public_key_y))
示例2: test_equality
# 需要導入模塊: from Cryptodome.PublicKey import ECC [as 別名]
# 或者: from Cryptodome.PublicKey.ECC import construct [as 別名]
def test_equality(self):
private_key = ECC.construct(d=3, curve="P-256")
private_key2 = ECC.construct(d=3, curve="P-256")
private_key3 = ECC.construct(d=4, curve="P-256")
public_key = private_key.public_key()
public_key2 = private_key2.public_key()
public_key3 = private_key3.public_key()
self.assertEqual(private_key, private_key2)
self.assertNotEqual(private_key, private_key3)
self.assertEqual(public_key, public_key2)
self.assertNotEqual(public_key, public_key3)
self.assertNotEqual(public_key, private_key)
示例3: test_construct
# 需要導入模塊: from Cryptodome.PublicKey import ECC [as 別名]
# 或者: from Cryptodome.PublicKey.ECC import construct [as 別名]
def test_construct(self):
key = ECC.construct(curve="P-256", d=1)
self.failUnless(key.has_private())
self.assertEqual(key.pointQ, _curve.G)
key = ECC.construct(curve="P-256", point_x=_curve.Gx, point_y=_curve.Gy)
self.failIf(key.has_private())
self.assertEqual(key.pointQ, _curve.G)
# Other names
ECC.construct(curve="secp256r1", d=1)
ECC.construct(curve="prime256v1", d=1)
示例4: int
# 需要導入模塊: from Cryptodome.PublicKey import ECC [as 別名]
# 或者: from Cryptodome.PublicKey.ECC import construct [as 別名]
{'result': lambda x: x,
'qx': lambda x: int(x, 16),
'qy': lambda x: int(x, 16),
})
for idx, tv in enumerate(test_vectors_verify):
if isinstance(tv, basestring):
res = re.match("\[P-256,(SHA-[0-9]+)\]", tv)
assert res
hash_name = res.group(1).replace("-", "")
hash_module = load_hash_by_name(hash_name)
continue
hash_obj = hash_module.new(tv.msg)
key = ECC.construct(curve="P-256", point_x=tv.qx, point_y=tv.qy)
verifier = DSS.new(key, 'fips-186-3')
def positive_test(self, verifier=verifier, hash_obj=hash_obj, signature=tv.r+tv.s):
verifier.verify(hash_obj, signature)
def negative_test(self, verifier=verifier, hash_obj=hash_obj, signature=tv.r+tv.s):
self.assertRaises(ValueError, verifier.verify, hash_obj, signature)
if tv.result.startswith('p'):
setattr(FIPS_ECDSA_Tests, "test_verify_positive_%d" % idx, positive_test)
else:
setattr(FIPS_ECDSA_Tests, "test_verify_negative_%d" % idx, negative_test)
test_vectors_sign = load_tests(("Cryptodome", "SelfTest", "Signature", "test_vectors", "ECDSA"),