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


Python ECC.import_key方法代码示例

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


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

示例1: test_export_openssh_compressed

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import import_key [as 别名]
    def test_export_openssh_compressed(self):
        key_file = load_file("ecc_p384_public_openssh.txt", "rt")
        pub_key = ECC.import_key(key_file)

        key_file_compressed = pub_key.export_key(format="OpenSSH", compress=True)
        assert len(key_file) > len(key_file_compressed)
        self.assertEquals(pub_key, ECC.import_key(key_file_compressed))
开发者ID:Legrandin,项目名称:pycryptodome,代码行数:9,代码来源:test_import_ECC.py

示例2: test_compressed_curve

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

        # Compressed P-521 curve (Y-point is even)
        # openssl ecparam -name secp521r1 -genkey -noout -conv_form compressed -out /tmp/a.pem
        # openssl ec -in /tmp/a.pem -text -noout
        pem1 = """-----BEGIN EC PRIVATE KEY-----
MIHcAgEBBEIAnm1CEjVjvNfXEN730p+D6su5l+mOztdc5XmTEoti+s2R4GQ4mAv3
0zYLvyklvOHw0+yy8d0cyGEJGb8T3ZVKmg2gBwYFK4EEACOhgYkDgYYABAHzjTI1
ckxQ3Togi0LAxiG0PucdBBBs5oIy3df95xv6SInp70z+4qQ2EltEmdNMssH8eOrl
M5CYdZ6nbcHMVaJUvQEzTrYxvFjOgJiOd+E9eBWbLkbMNqsh1UKVO6HbMbW0ohCI
uGxO8tM6r3w89/qzpG2SvFM/fvv3mIR30wSZDD84qA==
-----END EC PRIVATE KEY-----"""

        # Compressed P-521 curve (Y-point is odd)
        pem2 = """-----BEGIN EC PRIVATE KEY-----
MIHcAgEBBEIB84OfhJluLBRLn3+cC/RQ37C2SfQVP/t0gQK2tCsTf5avRcWYRrOJ
PmX9lNnkC0Hobd75QFRmdxrB0Wd1/M4jZOWgBwYFK4EEACOhgYkDgYYABAAMZcdJ
1YLCGHt3bHCEzdidVy6+brlJIbv1aQ9fPQLF7WKNv4c8w3H8d5a2+SDZilBOsk5c
6cNJDMz2ExWQvxl4CwDJtJGt1+LHVKFGy73NANqVxMbRu+2F8lOxkNp/ziFTbVyV
vv6oYkMIIi7r5oQWAiQDrR2mlrrFDL9V7GH/r8SWQw==
-----END EC PRIVATE KEY-----"""

        key1 = ECC.import_key(pem1)
        low16 = int(key1.pointQ.y % 65536)
        self.assertEqual(low16, 0x38a8)

        key2 = ECC.import_key(pem2)
        low16 = int(key2.pointQ.y % 65536)
        self.assertEqual(low16, 0x9643)
开发者ID:Legrandin,项目名称:pycryptodome,代码行数:31,代码来源:test_import_ECC.py

示例3: test_import_private_pem_encrypted

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import import_key [as 别名]
    def test_import_private_pem_encrypted(self):
        for algo in "des3", "aes128", "aes192", "aes256", "aes256_gcm":
            key_file = load_file("ecc_p521_private_enc_%s.pem" % algo)

            key = ECC.import_key(key_file, "secret")
            self.assertEqual(self.ref_private, key)

            key = ECC.import_key(tostr(key_file), b"secret")
            self.assertEqual(self.ref_private, key)
开发者ID:Legrandin,项目名称:pycryptodome,代码行数:11,代码来源:test_import_ECC.py

示例4: decrypt_with_ecc

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import import_key [as 别名]
def decrypt_with_ecc(private_ecc_key, random_pubkey_str, nonce, ctx, tag):
    """Takes elliptic curve isntance (private_ecc_key) and a byte string
    (message), and decrypts the ciphertext (ctx) after verifying the
    tag.

    """
    assert isinstance(private_ecc_key, ECC.EccKey), \
        "private_ecc_key should be ECC key. Got {}" \
            .format(type(private_ecc_key))

    # parse the ciphertext
    random_ecc_key = ECC.import_key(random_pubkey_str)
    new_point = random_ecc_key.pointQ * private_ecc_key.d
    h = SHA256.new(str(new_point.x))
    h.update(str(new_point.y))
    key = h.digest()
    if not nonce:
        nonce = os.urandom(16)
    aes_engine = AES.new(key=key, mode=AES.MODE_EAX, nonce=nonce)
    msg = ''
    try:
        msg = aes_engine.decrypt_and_verify(ctx, tag)
    except ValueError:
        print "The tag verification failed. Means: ciphertext has been "\
            "tampered or key is incorrect" 
    return msg
开发者ID:rchatterjee,项目名称:pam-typopw,代码行数:28,代码来源:pwcryptolib.py

示例5: import_public_key

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import import_key [as 别名]
def import_public_key(public_key):
    """
    Import a plain text public key and make it into an ECC object 
    :param public_key: the public key as a string
    :return: an ECC key object
    """
    return ECC.import_key(public_key)
开发者ID:Nurraku,项目名称:ABC,代码行数:9,代码来源:wallet.py

示例6: test_export_public_der_compressed

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import import_key [as 别名]
    def test_export_public_der_compressed(self):
        key_file = load_file("ecc_p521_public.der")
        pub_key = ECC.import_key(key_file)
        key_file_compressed = pub_key.export_key(format="DER", compress=True)

        key_file_compressed_ref = load_file("ecc_p521_public_compressed.der")
        self.assertEqual(key_file_compressed, key_file_compressed_ref)
开发者ID:Legrandin,项目名称:pycryptodome,代码行数:9,代码来源:test_import_ECC.py

示例7: test_unsupported_curve

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

        # openssl ecparam -name secp224r1 -genkey -noout -out strange-curve.pem -conv_form uncompressed
        curve = """-----BEGIN EC PRIVATE KEY-----
MGgCAQEEHEi7xTHW+5oT8wgpjoEKV7uwMuY8rt2YUZe4j1SgBwYFK4EEACGhPAM6
AATJgfOG+Bnki8robpNM8MtArji43GU9up4B0x9sVhqB+fZP+hXgV9ITN7YX4E/k
gVnJp9EBND/tHQ==
-----END EC PRIVATE KEY-----"""

        from Crypto.PublicKey.ECC import UnsupportedEccFeature
        try:
            ECC.import_key(curve)
        except UnsupportedEccFeature as uef:
            assert("1.3.132.0.33" in str(uef))
        else:
            assert(False)
开发者ID:Legrandin,项目名称:pycryptodome,代码行数:18,代码来源:test_import_ECC.py

示例8: test_import_openssh

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import import_key [as 别名]
    def test_import_openssh(self):
        key_file = load_file("ecc_p521_public_openssh.txt")

        key = ECC._import_openssh(key_file)
        self.assertEqual(self.ref_public, key)

        key = ECC.import_key(key_file)
        self.assertEqual(self.ref_public, key)
开发者ID:Legrandin,项目名称:pycryptodome,代码行数:10,代码来源:test_import_ECC.py

示例9: test_export_public_pem_compressed

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import import_key [as 别名]
    def test_export_public_pem_compressed(self):
        key_file = load_file("ecc_p384_public.pem", "rt").strip()
        pub_key = ECC.import_key(key_file)

        key_file_compressed = pub_key.export_key(format="PEM", compress=True)
        key_file_compressed_ref = load_file("ecc_p384_public_compressed.pem", "rt").strip()

        self.assertEqual(key_file_compressed, key_file_compressed_ref)
开发者ID:Legrandin,项目名称:pycryptodome,代码行数:10,代码来源:test_import_ECC.py

示例10: test_import_x509_der

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import import_key [as 别名]
    def test_import_x509_der(self):
        key_file = load_file("ecc_p521_x509.der")

        key = ECC._import_der(key_file, None)
        self.assertEqual(self.ref_public, key)

        key = ECC.import_key(key_file)
        self.assertEqual(self.ref_public, key)
开发者ID:Legrandin,项目名称:pycryptodome,代码行数:10,代码来源:test_import_ECC.py

示例11: test_import_private_pkcs8_encrypted_1

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import import_key [as 别名]
    def test_import_private_pkcs8_encrypted_1(self):
        key_file = load_file("ecc_p521_private_p8.der")

        key = ECC._import_der(key_file, "secret")
        self.assertEqual(self.ref_private, key)

        key = ECC.import_key(key_file, "secret")
        self.assertEqual(self.ref_private, key)
开发者ID:Legrandin,项目名称:pycryptodome,代码行数:10,代码来源:test_import_ECC.py

示例12: test_import_private_pkcs8_clear

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import import_key [as 别名]
    def test_import_private_pkcs8_clear(self):
        key_file = load_file("ecc_p521_private_p8_clear.der")

        key = ECC._import_der(key_file, None)
        self.assertEqual(self.ref_private, key)

        key = ECC.import_key(key_file)
        self.assertEqual(self.ref_private, key)
开发者ID:Legrandin,项目名称:pycryptodome,代码行数:10,代码来源:test_import_ECC.py

示例13: test_export_private_pem_encrypted

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import import_key [as 别名]
    def test_export_private_pem_encrypted(self):
        encoded = self.ref_private._export_private_pem(passphrase=b"secret")

        # This should prove that the output is password-protected
        self.assertRaises(ValueError, ECC.import_key, encoded)

        assert "EC PRIVATE KEY" in encoded

        decoded = ECC.import_key(encoded, "secret")
        self.assertEqual(self.ref_private, decoded)

        # ---

        encoded = self.ref_private.export_key(format="PEM",
                                         passphrase="secret",
                                         use_pkcs8=False)
        decoded = ECC.import_key(encoded, "secret")
        self.assertEqual(self.ref_private, decoded)
开发者ID:Legrandin,项目名称:pycryptodome,代码行数:20,代码来源:test_import_ECC.py

示例14: test_import_private_der

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import import_key [as 别名]
    def test_import_private_der(self):
        key_file = load_file("ecc_p384_private.der")

        key = ECC._import_private_der(key_file, None)
        self.assertEqual(self.ref_private, key)

        key = ECC._import_der(key_file, None)
        self.assertEqual(self.ref_private, key)

        key = ECC.import_key(key_file)
        self.assertEqual(self.ref_private, key)
开发者ID:Legrandin,项目名称:pycryptodome,代码行数:13,代码来源:test_import_ECC.py

示例15: test_import_public_der

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import import_key [as 别名]
    def test_import_public_der(self):
        key_file = load_file("ecc_p521_public.der")

        key = ECC._import_subjectPublicKeyInfo(key_file)
        self.assertEqual(self.ref_public, key)

        key = ECC._import_der(key_file, None)
        self.assertEqual(self.ref_public, key)

        key = ECC.import_key(key_file)
        self.assertEqual(self.ref_public, key)
开发者ID:Legrandin,项目名称:pycryptodome,代码行数:13,代码来源:test_import_ECC.py


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