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


Python ECC.generate方法代码示例

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


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

示例1: test_generate

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import generate [as 别名]
    def test_generate(self):

        key = ECC.generate(curve="P-256")
        self.assertTrue(key.has_private())
        self.assertEqual(key.pointQ, EccPoint(_curve.Gx, _curve.Gy) * key.d)

        # Other names
        ECC.generate(curve="secp256r1")
        ECC.generate(curve="prime256v1")
开发者ID:shubhanus,项目名称:taiga,代码行数:11,代码来源:test_ECC.py

示例2: test_generate

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import generate [as 别名]
    def test_generate(self):

        curve = _curves['p521']
        key = ECC.generate(curve="P-521")
        self.failUnless(key.has_private())
        self.assertEqual(key.pointQ, EccPoint(curve.Gx, curve.Gy, "p521") * key.d)

        # Other names
        ECC.generate(curve="secp521r1")
        ECC.generate(curve="prime521v1")
开发者ID:Legrandin,项目名称:pycryptodome,代码行数:12,代码来源:test_ECC.py

示例3: test_mix

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import generate [as 别名]
    def test_mix(self):

        p1 = ECC.generate(curve='P-256').pointQ
        p2 = ECC.generate(curve='P-384').pointQ

        try:
            p1 + p2
            assert(False)
        except ValueError as e:
            assert "not on the same curve" in str(e)

        try:
            p1 += p2
            assert(False)
        except ValueError as e:
            assert "not on the same curve" in str(e)
开发者ID:Legrandin,项目名称:pycryptodome,代码行数:18,代码来源:test_ECC.py

示例4: generate_from_pw

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import generate [as 别名]
 def generate_from_pw(pw, salt, curve='P-256'):
     """Generates a ECC key pair using the randomness derived from pw, salt. 
     """
     rand_seed = PBKDF2(pw, salt, dkLen=16, count=HASH_CNT)
     rand_num_generator = RandomWSeed(rand_seed, 1024)
     return ECC.generate(
         curve=curve, 
         randfunc=rand_num_generator.get_random_bytes
     )
开发者ID:rchatterjee,项目名称:pam-typopw,代码行数:11,代码来源:pwcryptolib.py

示例5: test_compute_id_w_saltctx

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import generate [as 别名]
def test_compute_id_w_saltctx():
    pwtypo = 'asdfadsfadf'
    list_keys = {
        i: ECC.generate(curve='P-256')
        for i in xrange(10)
    }
    pk_dict = {k: v.public_key() for k,v in list_keys.items()}
    salt = os.urandom(32)
    saltctx = encrypt(pk_dict, salt)
    id1 = compute_id_w_saltctx(pwtypo, dict([list_keys.popitem()]), saltctx)
    id2 = compute_id_w_saltctx(pwtypo, dict([list_keys.popitem()]), saltctx)
    assert isinstance(id1, int)
    assert id1 == id2
开发者ID:rchatterjee,项目名称:pam-typopw,代码行数:15,代码来源:test_pw_pkcrypto.py

示例6: test_functionality

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import generate [as 别名]
def test_functionality():
    # generate a set of pk,sk pairs
    list_keys = {
        i: ECC.generate(curve='P-256')
        for i in xrange(10)
    }
    pk_dict = {k: v.public_key() for k,v in list_keys.items()}
    msg = 'HI Multiuser! in (test_functionality)'
    ctx = encrypt(pk_dict, msg)
    while list_keys:
        sk_dict = dict([list_keys.popitem()])
        _msg = decrypt(sk_dict, ctx)
        assert msg == _msg, "\n_msg={}\n msg={}\n".format(_msg, msg)
开发者ID:rchatterjee,项目名称:pam-typopw,代码行数:15,代码来源:test_pw_pkcrypto.py

示例7: get_private_key

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import generate [as 别名]
def get_private_key():
    """
    Set the private key from a file or by creating a new one
    :return: ECC private key object
    """
    ensure_data_dir()  # ensure directory exists
    try:  # get existing private key
        key = ECC.import_key(open(_PRIVATE_KEY_PATH, 'rt').read())
    except FileNotFoundError:  # create public key
        key = ECC.generate(curve='P-256')
        # write private key to file
        file = open(_PRIVATE_KEY_PATH, 'wt')
        file.write(key.export_key(format='PEM'))
        file.close()

    return key
开发者ID:Nurraku,项目名称:ABC,代码行数:18,代码来源:wallet.py

示例8: encrypt_with_ecc

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import generate [as 别名]
def encrypt_with_ecc(public_ecc_key, message, nonce=None):
    """Takes elliptic curve isntance (public_ecc_key) and a byte string
    (message), and outputs a ciphertext
    """
    assert isinstance(public_ecc_key, ECC.EccKey),\
        "public_ecc_key should be ECC key. Got {}".format(type(public_ecc_key))
    random_ecc_key = ECC.generate(curve=public_ecc_key.curve)
    new_point = public_ecc_key.pointQ * random_ecc_key.d
    h = SHA256.new(str(new_point.x))
    h.update('XXX' + str(new_point.y)) # 'XXX' is a delimiter
    key = h.digest()
    if not nonce:
        nonce = os.urandom(16)
    aes_engine = AES.new(key=key, mode=AES.MODE_EAX, nonce=nonce)
    ctx, tag = aes_engine.encrypt_and_digest(message)
    # Return: <ephemeral_pub_key>, <nonce>, <ciphertext>, <tag>
    return (random_ecc_key.public_key().export_key(format='OpenSSH'),
            aes_engine.nonce, ctx, tag)
开发者ID:rchatterjee,项目名称:pam-typopw,代码行数:20,代码来源:pwcryptolib.py

示例9: generate

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import generate [as 别名]
 def generate(pwhash, curve='secp256r1'):
     rand_num_generator = RandomWSeed(pwhash, 1024)
     return ECC.generate(
         curve=curve, 
         randfunc=rand_num_generator.get_random_bytes
     )
开发者ID:rchatterjee,项目名称:pam-typopw,代码行数:8,代码来源:pwcryptolib.py

示例10: generate_key_pair

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import generate [as 别名]
def generate_key_pair():
    private_key = ECC.generate(curve='P-256')
    public_key = private_key.public_key()
    return public_key, private_key
开发者ID:rchatterjee,项目名称:pam-typopw,代码行数:6,代码来源:pycryptodome_pwpkcrypto.py


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