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


Python asymmetric.load_public_key方法代碼示例

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


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

示例1: test_rsa_generate

# 需要導入模塊: from oscrypto import asymmetric [as 別名]
# 或者: from oscrypto.asymmetric import load_public_key [as 別名]
def test_rsa_generate(self):
        public, private = asymmetric.generate_pair('rsa', bit_size=2048)

        self.assertEqual('rsa', public.algorithm)
        self.assertEqual(2048, public.bit_size)

        original_data = b'This is data to sign'
        signature = asymmetric.rsa_pkcs1v15_sign(private, original_data, 'sha1')
        self.assertIsInstance(signature, byte_cls)
        asymmetric.rsa_pkcs1v15_verify(public, signature, original_data, 'sha1')

        raw_public = asymmetric.dump_public_key(public)
        asymmetric.load_public_key(raw_public)
        raw_private = asymmetric.dump_private_key(private, None)
        asymmetric.load_private_key(raw_private, None)

        self.assertIsInstance(private.fingerprint, byte_cls)
        self.assertIsInstance(public.fingerprint, byte_cls)
        self.assertEqual(private.fingerprint, public.fingerprint) 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:21,代碼來源:test_asymmetric.py

示例2: test_ec_generate

# 需要導入模塊: from oscrypto import asymmetric [as 別名]
# 或者: from oscrypto.asymmetric import load_public_key [as 別名]
def test_ec_generate(self):
        public, private = asymmetric.generate_pair('ec', curve='secp256r1')

        self.assertEqual('ec', public.algorithm)
        self.assertEqual('secp256r1', public.asn1.curve[1])

        original_data = b'This is data to sign'
        signature = asymmetric.ecdsa_sign(private, original_data, 'sha1')
        self.assertIsInstance(signature, byte_cls)
        asymmetric.ecdsa_verify(public, signature, original_data, 'sha1')

        raw_public = asymmetric.dump_public_key(public)
        asymmetric.load_public_key(raw_public)
        raw_private = asymmetric.dump_private_key(private, None)
        asymmetric.load_private_key(raw_private, None)

        self.assertIsInstance(private.fingerprint, byte_cls)
        self.assertIsInstance(public.fingerprint, byte_cls)
        self.assertEqual(private.fingerprint, public.fingerprint) 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:21,代碼來源:test_asymmetric.py

示例3: test_dsa_2048_sha1_sign

# 需要導入模塊: from oscrypto import asymmetric [as 別名]
# 或者: from oscrypto.asymmetric import load_public_key [as 別名]
def test_dsa_2048_sha1_sign(self):
        def do_run():
            original_data = b'This is data to sign'
            private = asymmetric.load_private_key(os.path.join(fixtures_dir, 'keys/test-dsa-2048.key'))
            public = asymmetric.load_public_key(os.path.join(fixtures_dir, 'keys/test-dsa-2048.crt'))

            signature = asymmetric.dsa_sign(private, original_data, 'sha1')
            self.assertIsInstance(signature, byte_cls)

            asymmetric.dsa_verify(public, signature, original_data, 'sha1')

        if sys.platform == 'win32':
            with self.assertRaises(errors.AsymmetricKeyError):
                do_run()
        else:
            do_run() 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:18,代碼來源:test_asymmetric.py

示例4: test_dsa_3072_sign

# 需要導入模塊: from oscrypto import asymmetric [as 別名]
# 或者: from oscrypto.asymmetric import load_public_key [as 別名]
def test_dsa_3072_sign(self):
        def do_run():
            original_data = b'This is data to sign'
            private = asymmetric.load_private_key(os.path.join(fixtures_dir, 'keys/test-dsa.key'))
            public = asymmetric.load_public_key(os.path.join(fixtures_dir, 'keys/test-dsa.crt'))

            signature = asymmetric.dsa_sign(private, original_data, 'sha256')
            self.assertIsInstance(signature, byte_cls)

            asymmetric.dsa_verify(public, signature, original_data, 'sha256')

        if not _should_support_sha2():
            with self.assertRaises(errors.AsymmetricKeyError):
                do_run()
        else:
            do_run() 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:18,代碼來源:test_asymmetric.py

示例5: test_dsa_3072_sign_sha1

# 需要導入模塊: from oscrypto import asymmetric [as 別名]
# 或者: from oscrypto.asymmetric import load_public_key [as 別名]
def test_dsa_3072_sign_sha1(self):
        def do_run():
            original_data = b'This is data to sign'
            private = asymmetric.load_private_key(os.path.join(fixtures_dir, 'keys/test-dsa.key'))
            public = asymmetric.load_public_key(os.path.join(fixtures_dir, 'keys/test-dsa.crt'))

            signature = asymmetric.dsa_sign(private, original_data, 'sha1')
            self.assertIsInstance(signature, byte_cls)

            asymmetric.dsa_verify(public, signature, original_data, 'sha1')

        if _backend == 'mac' or openssl_098 or _backend == 'winlegacy':
            with self.assertRaises(errors.AsymmetricKeyError):
                do_run()
        elif _backend == 'win':
            if _win_version_pair() < (6, 2):
                exception_class = errors.AsymmetricKeyError
            else:
                exception_class = ValueError
            with self.assertRaises(exception_class):
                do_run()
        else:
            do_run() 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:25,代碼來源:test_asymmetric.py

示例6: test_load_incomplete_dsa_cert

# 需要導入模塊: from oscrypto import asymmetric [as 別名]
# 或者: from oscrypto.asymmetric import load_public_key [as 別名]
def test_load_incomplete_dsa_cert(self):
        with self.assertRaises(errors.IncompleteAsymmetricKeyError):
            asymmetric.load_public_key(os.path.join(fixtures_dir, 'DSAParametersInheritedCACert.crt')) 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:5,代碼來源:test_asymmetric.py

示例7: test_public_key_attributes

# 需要導入模塊: from oscrypto import asymmetric [as 別名]
# 或者: from oscrypto.asymmetric import load_public_key [as 別名]
def test_public_key_attributes(self):
        pub_key = asymmetric.load_public_key(os.path.join(fixtures_dir, 'keys/test-public-rsa.key'))
        self.assertEqual(2048, pub_key.bit_size)
        self.assertEqual(256, pub_key.byte_size)
        self.assertEqual('rsa', pub_key.algorithm) 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:7,代碼來源:test_asymmetric.py

示例8: test_public_key_ec_attributes

# 需要導入模塊: from oscrypto import asymmetric [as 別名]
# 或者: from oscrypto.asymmetric import load_public_key [as 別名]
def test_public_key_ec_attributes(self):
        pub_key = asymmetric.load_public_key(os.path.join(fixtures_dir, 'keys/test-public-ec-named.key'))
        self.assertEqual(256, pub_key.bit_size)
        self.assertEqual(32, pub_key.byte_size)
        self.assertEqual('secp256r1', pub_key.curve)
        self.assertEqual('ec', pub_key.algorithm) 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:8,代碼來源:test_asymmetric.py

示例9: test_dump_public

# 需要導入模塊: from oscrypto import asymmetric [as 別名]
# 或者: from oscrypto.asymmetric import load_public_key [as 別名]
def test_dump_public(self):
        public = asymmetric.load_public_key(os.path.join(fixtures_dir, 'keys/test.crt'))
        pem_serialized = asymmetric.dump_public_key(public)
        public_reloaded = asymmetric.load_public_key(pem_serialized)
        self.assertIsInstance(public_reloaded, asymmetric.PublicKey)
        self.assertEqual('rsa', public_reloaded.algorithm) 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:8,代碼來源:test_asymmetric.py

示例10: test_rsa_verify

# 需要導入模塊: from oscrypto import asymmetric [as 別名]
# 或者: from oscrypto.asymmetric import load_public_key [as 別名]
def test_rsa_verify(self):
        with open(os.path.join(fixtures_dir, 'message.txt'), 'rb') as f:
            original_data = f.read()
        with open(os.path.join(fixtures_dir, 'rsa_signature'), 'rb') as f:
            signature = f.read()
        public = asymmetric.load_public_key(os.path.join(fixtures_dir, 'keys/test.crt'))
        asymmetric.rsa_pkcs1v15_verify(public, signature, original_data, 'sha1') 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:9,代碼來源:test_asymmetric.py

示例11: test_rsa_verify_key_size_mismatch

# 需要導入模塊: from oscrypto import asymmetric [as 別名]
# 或者: from oscrypto.asymmetric import load_public_key [as 別名]
def test_rsa_verify_key_size_mismatch(self):
        with open(os.path.join(fixtures_dir, 'message.txt'), 'rb') as f:
            original_data = f.read()
        with open(os.path.join(fixtures_dir, 'rsa_signature'), 'rb') as f:
            signature = f.read()
        public = asymmetric.load_public_key(os.path.join(fixtures_dir, 'keys/test-4096.crt'))
        with self.assertRaises(errors.SignatureError):
            asymmetric.rsa_pkcs1v15_verify(public, signature, original_data, 'sha1') 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:10,代碼來源:test_asymmetric.py

示例12: test_rsa_verify_fail

# 需要導入模塊: from oscrypto import asymmetric [as 別名]
# 或者: from oscrypto.asymmetric import load_public_key [as 別名]
def test_rsa_verify_fail(self):
        with open(os.path.join(fixtures_dir, 'message.txt'), 'rb') as f:
            original_data = f.read()
        with open(os.path.join(fixtures_dir, 'rsa_signature'), 'rb') as f:
            signature = f.read()
        public = asymmetric.load_public_key(os.path.join(fixtures_dir, 'keys/test.crt'))
        with self.assertRaises(errors.SignatureError):
            asymmetric.rsa_pkcs1v15_verify(public, signature, original_data + b'1', 'sha1') 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:10,代碼來源:test_asymmetric.py

示例13: test_rsa_verify_fail_each_byte

# 需要導入模塊: from oscrypto import asymmetric [as 別名]
# 或者: from oscrypto.asymmetric import load_public_key [as 別名]
def test_rsa_verify_fail_each_byte(self):
        with open(os.path.join(fixtures_dir, 'message.txt'), 'rb') as f:
            original_data = f.read()
        with open(os.path.join(fixtures_dir, 'rsa_signature'), 'rb') as f:
            original_signature = f.read()
        public = asymmetric.load_public_key(os.path.join(fixtures_dir, 'keys/test.crt'))
        for i in range(0, len(original_signature)):
            if i == 0:
                signature = b'\xab' + original_signature[1:]
            elif i == len(original_signature) - 1:
                signature = original_signature[0:-1] + b'\xab'
            else:
                signature = original_signature[0:i] + b'\xab' + original_signature[i + 1:]
            with self.assertRaises(errors.SignatureError):
                asymmetric.rsa_pkcs1v15_verify(public, signature, original_data + b'1', 'sha1') 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:17,代碼來源:test_asymmetric.py

示例14: test_rsa_pss_verify_fail

# 需要導入模塊: from oscrypto import asymmetric [as 別名]
# 或者: from oscrypto.asymmetric import load_public_key [as 別名]
def test_rsa_pss_verify_fail(self):
        with open(os.path.join(fixtures_dir, 'message.txt'), 'rb') as f:
            original_data = f.read()
        with open(os.path.join(fixtures_dir, 'rsa_pss_signature'), 'rb') as f:
            signature = f.read()
        public = asymmetric.load_public_key(os.path.join(fixtures_dir, 'keys/test.crt'))
        with self.assertRaises(errors.SignatureError):
            asymmetric.rsa_pss_verify(public, signature, original_data + b'1', 'sha1') 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:10,代碼來源:test_asymmetric.py

示例15: test_rsa_raw_verify

# 需要導入模塊: from oscrypto import asymmetric [as 別名]
# 或者: from oscrypto.asymmetric import load_public_key [as 別名]
def test_rsa_raw_verify(self):
        with open(os.path.join(fixtures_dir, 'message.txt'), 'rb') as f:
            original_data = f.read()
        with open(os.path.join(fixtures_dir, 'rsa_signature_raw'), 'rb') as f:
            signature = f.read()
        public = asymmetric.load_public_key(os.path.join(fixtures_dir, 'keys/test.crt'))
        asymmetric.rsa_pkcs1v15_verify(public, signature, original_data, 'raw') 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:9,代碼來源:test_asymmetric.py


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