當前位置: 首頁>>代碼示例>>Python>>正文


Python ECC.import_key方法代碼示例

本文整理匯總了Python中Cryptodome.PublicKey.ECC.import_key方法的典型用法代碼示例。如果您正苦於以下問題:Python ECC.import_key方法的具體用法?Python ECC.import_key怎麽用?Python ECC.import_key使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cryptodome.PublicKey.ECC的用法示例。


在下文中一共展示了ECC.import_key方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_export_openssh_compressed

# 需要導入模塊: from Cryptodome.PublicKey import ECC [as 別名]
# 或者: from Cryptodome.PublicKey.ECC import import_key [as 別名]
    def test_export_openssh_compressed(self):
        key_file = load_file("ecc_p256_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:chevah,項目名稱:python-package,代碼行數:9,代碼來源:test_import_ECC.py

示例2: test_import_private_pem_encrypted

# 需要導入模塊: from Cryptodome.PublicKey import ECC [as 別名]
# 或者: from Cryptodome.PublicKey.ECC import import_key [as 別名]
    def test_import_private_pem_encrypted(self):
        for algo in "des3", : # TODO: , "aes128", "aes192", "aes256_gcm":
            key_file = load_file("ecc_p256_private_enc_%s.pem" % algo)

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

            key = ECC.import_key(tostr(key_file), b("secret"))
            self.assertEqual(ref_private, key)
開發者ID:FndNur1Labs,項目名稱:PokemonGo-DesktopMap,代碼行數:11,代碼來源:test_import_ECC.py

示例3: test_export_public_der_compressed

# 需要導入模塊: from Cryptodome.PublicKey import ECC [as 別名]
# 或者: from Cryptodome.PublicKey.ECC import import_key [as 別名]
    def test_export_public_der_compressed(self):
        key_file = load_file("ecc_p256_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_p256_public_compressed.der")
        self.assertEqual(key_file_compressed, key_file_compressed_ref)
開發者ID:chevah,項目名稱:python-package,代碼行數:9,代碼來源:test_import_ECC.py

示例4: test_unsupported_curve

# 需要導入模塊: from Cryptodome.PublicKey import ECC [as 別名]
# 或者: from Cryptodome.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 Cryptodome.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:chevah,項目名稱:python-package,代碼行數:18,代碼來源:test_import_ECC.py

示例5: add_tests

# 需要導入模塊: from Cryptodome.PublicKey import ECC [as 別名]
# 或者: from Cryptodome.PublicKey.ECC import import_key [as 別名]
    def add_tests(self, filename):
        comps = "Cryptodome.SelfTest.Signature.test_vectors.wycheproof".split(".")
        with open(pycryptodome_filename(comps, filename), "rt") as file_in:
            tv_tree = json.load(file_in)

        for group in tv_tree['testGroups']:
            
            try:
                key = ECC.import_key(group['keyPem'])
            except ValueError:
                continue
            
            hash_name = group['sha']
            if hash_name == "SHA-256":
                hash_module = SHA256
            elif hash_name == "SHA-224":
                hash_module = SHA224
            elif hash_name == "SHA-1":
                hash_module = SHA1
            else:
                assert False
            assert group['type'] == "ECDSAVer"
            
            for test in group['tests']:
                tv = TestVector()
                
                tv.id = test['tcId']
                tv.comment = test['comment']
                for attr in 'msg', 'sig':
                    setattr(tv, attr, unhexlify(test[attr]))
                tv.key = key
                tv.hash_module = hash_module
                tv.valid = test['result'] != "invalid"
                tv.warning = test['result'] == "acceptable"
                self.tv.append(tv)
開發者ID:chevah,項目名稱:python-package,代碼行數:37,代碼來源:test_dss.py

示例6: test_import_private_pkcs8_clear

# 需要導入模塊: from Cryptodome.PublicKey import ECC [as 別名]
# 或者: from Cryptodome.PublicKey.ECC import import_key [as 別名]
    def test_import_private_pkcs8_clear(self):
        key_file = load_file("ecc_p256_private_p8_clear.der")

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

        key = ECC.import_key(key_file)
        self.assertEqual(ref_private, key)
開發者ID:FndNur1Labs,項目名稱:PokemonGo-DesktopMap,代碼行數:10,代碼來源:test_import_ECC.py

示例7: test_export_public_pem_compressed

# 需要導入模塊: from Cryptodome.PublicKey import ECC [as 別名]
# 或者: from Cryptodome.PublicKey.ECC import import_key [as 別名]
    def test_export_public_pem_compressed(self):
        key_file = load_file("ecc_p256_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_p256_public_compressed.pem", "rt").strip()

        self.assertEqual(key_file_compressed, key_file_compressed_ref)
開發者ID:chevah,項目名稱:python-package,代碼行數:10,代碼來源:test_import_ECC.py

示例8: test_import_private_pkcs8_encrypted_1

# 需要導入模塊: from Cryptodome.PublicKey import ECC [as 別名]
# 或者: from Cryptodome.PublicKey.ECC import import_key [as 別名]
    def test_import_private_pkcs8_encrypted_1(self):
        key_file = load_file("ecc_p256_private_p8.der")

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

        key = ECC.import_key(key_file, "secret")
        self.assertEqual(ref_private, key)
開發者ID:FndNur1Labs,項目名稱:PokemonGo-DesktopMap,代碼行數:10,代碼來源:test_import_ECC.py

示例9: test_import_x509_der

# 需要導入模塊: from Cryptodome.PublicKey import ECC [as 別名]
# 或者: from Cryptodome.PublicKey.ECC import import_key [as 別名]
    def test_import_x509_der(self):
        key_file = load_file("ecc_p256_x509.der")

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

        key = ECC.import_key(key_file)
        self.assertEqual(ref_public, key)
開發者ID:FndNur1Labs,項目名稱:PokemonGo-DesktopMap,代碼行數:10,代碼來源:test_import_ECC.py

示例10: test_import_openssh

# 需要導入模塊: from Cryptodome.PublicKey import ECC [as 別名]
# 或者: from Cryptodome.PublicKey.ECC import import_key [as 別名]
    def test_import_openssh(self):
        key_file = load_file("ecc_p256_public_openssh.txt")

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

        key = ECC.import_key(key_file)
        self.assertEqual(ref_public, key)
開發者ID:FndNur1Labs,項目名稱:PokemonGo-DesktopMap,代碼行數:10,代碼來源:test_import_ECC.py

示例11: test_export_private_pem_encrypted

# 需要導入模塊: from Cryptodome.PublicKey import ECC [as 別名]
# 或者: from Cryptodome.PublicKey.ECC import import_key [as 別名]
    def test_export_private_pem_encrypted(self):
        encoded = 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(ref_private, decoded)

        # ---

        encoded = ref_private.export_key(format="PEM",
                                         passphrase="secret",
                                         use_pkcs8=False)
        decoded = ECC.import_key(encoded, "secret")
        self.assertEqual(ref_private, decoded)
開發者ID:FndNur1Labs,項目名稱:PokemonGo-DesktopMap,代碼行數:20,代碼來源:test_import_ECC.py

示例12: test_import_public_der

# 需要導入模塊: from Cryptodome.PublicKey import ECC [as 別名]
# 或者: from Cryptodome.PublicKey.ECC import import_key [as 別名]
    def test_import_public_der(self):
        key_file = load_file("ecc_p256_public.der")

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

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

        key = ECC.import_key(key_file)
        self.assertEqual(ref_public, key)
開發者ID:FndNur1Labs,項目名稱:PokemonGo-DesktopMap,代碼行數:13,代碼來源:test_import_ECC.py

示例13: test_export_private_pkcs8_and_pem_2

# 需要導入模塊: from Cryptodome.PublicKey import ECC [as 別名]
# 或者: from Cryptodome.PublicKey.ECC import import_key [as 別名]
    def test_export_private_pkcs8_and_pem_2(self):
        # PKCS8 inside PEM with PKCS8 encryption
        encoded = ref_private._export_private_encrypted_pkcs8_in_clear_pem("secret",
                              protection="PBKDF2WithHMAC-SHA1AndAES128-CBC")

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

        assert "ENCRYPTED PRIVATE KEY" in encoded

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

        # ---

        encoded = ref_private.export_key(format="PEM",
                                         passphrase="secret",
                                         protection="PBKDF2WithHMAC-SHA1AndAES128-CBC")
        decoded = ECC.import_key(encoded, "secret")
        self.assertEqual(ref_private, decoded)
開發者ID:FndNur1Labs,項目名稱:PokemonGo-DesktopMap,代碼行數:22,代碼來源:test_import_ECC.py

示例14: test_compressed_curve

# 需要導入模塊: from Cryptodome.PublicKey import ECC [as 別名]
# 或者: from Cryptodome.PublicKey.ECC import import_key [as 別名]
    def test_compressed_curve(self):

        # Compressed P-256 curve (Y-point is even)
        pem1 = """-----BEGIN EC PRIVATE KEY-----
        MFcCAQEEIHTuc09jC51xXomV6MVCDN+DpAAvSmaJWZPTEHM6D5H1oAoGCCqGSM49
        AwEHoSQDIgACWFuGbHe8yJ43rir7PMTE9w8vHz0BSpXHq90Xi7/s+a0=
        -----END EC PRIVATE KEY-----"""

        # Compressed P-256 curve (Y-point is odd)
        pem2 = """-----BEGIN EC PRIVATE KEY-----
        MFcCAQEEIFggiPN9SQP+FAPTCPp08fRUz7rHp2qNBRcBJ1DXhb3ZoAoGCCqGSM49
        AwEHoSQDIgADLpph1trTIlVfa8NJvlMUPyWvL+wP+pW3BJITUL/wj9A=
        -----END EC PRIVATE KEY-----"""

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

        key2 = ECC.import_key(pem2)
        low16 = int(key2.pointQ.y % 65536)
        self.assertEqual(low16, 0x6E57)
開發者ID:chevah,項目名稱:python-package,代碼行數:23,代碼來源:test_import_ECC.py

示例15: test_export_private_pkcs8_encrypted

# 需要導入模塊: from Cryptodome.PublicKey import ECC [as 別名]
# 或者: from Cryptodome.PublicKey.ECC import import_key [as 別名]
    def test_export_private_pkcs8_encrypted(self):
        encoded = ref_private._export_pkcs8(passphrase="secret",
                                            protection="PBKDF2WithHMAC-SHA1AndAES128-CBC")

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

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

        # ---

        encoded = ref_private.export_key(format="DER",
                                         passphrase="secret",
                                         protection="PBKDF2WithHMAC-SHA1AndAES128-CBC")
        decoded = ECC.import_key(encoded, "secret")
        self.assertEqual(ref_private, decoded)
開發者ID:FndNur1Labs,項目名稱:PokemonGo-DesktopMap,代碼行數:19,代碼來源:test_import_ECC.py


注:本文中的Cryptodome.PublicKey.ECC.import_key方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。