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


Python asymmetric.ecdsa_sign方法代碼示例

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


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

示例1: test_ec_generate

# 需要導入模塊: from oscrypto import asymmetric [as 別名]
# 或者: from oscrypto.asymmetric import ecdsa_sign [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

示例2: sign_func

# 需要導入模塊: from oscrypto import asymmetric [as 別名]
# 或者: from oscrypto.asymmetric import ecdsa_sign [as 別名]
def sign_func(self, tbs_request, algo):
        if algo['algorithm'].native == 'sha256_rsa':
            algo = 'sha256'
        else:
            # OCSPResponseBuilder (used server-side) statically uses sha256, so this should never
            # happen for now.
            raise ValueError('Unknown algorithm: %s' % algo.native)

        # from ocspbuilder.OCSPResponseBuilder.build:
        if self.ocsp_private_key.algorithm == 'rsa':
            sign_func = asymmetric.rsa_pkcs1v15_sign
        elif self.ocsp_private_key.algorithm == 'dsa':
            sign_func = asymmetric.dsa_sign
        elif self.ocsp_private_key.algorithm == 'ec':
            sign_func = asymmetric.ecdsa_sign

        return sign_func(self.ocsp_private_key, tbs_request.dump(), algo) 
開發者ID:mathiasertl,項目名稱:django-ca,代碼行數:19,代碼來源:tests_views_ocsp.py

示例3: test_ecdsa_sign

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

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

        asymmetric.ecdsa_verify(public, signature, original_data, 'sha1') 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:11,代碼來源:test_asymmetric.py


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