本文整理汇总了Python中oscrypto.asymmetric.rsa_pkcs1v15_sign方法的典型用法代码示例。如果您正苦于以下问题:Python asymmetric.rsa_pkcs1v15_sign方法的具体用法?Python asymmetric.rsa_pkcs1v15_sign怎么用?Python asymmetric.rsa_pkcs1v15_sign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oscrypto.asymmetric
的用法示例。
在下文中一共展示了asymmetric.rsa_pkcs1v15_sign方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rsa_generate
# 需要导入模块: from oscrypto import asymmetric [as 别名]
# 或者: from oscrypto.asymmetric import rsa_pkcs1v15_sign [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)
示例2: sign_func
# 需要导入模块: from oscrypto import asymmetric [as 别名]
# 或者: from oscrypto.asymmetric import rsa_pkcs1v15_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)
示例3: test_rsa_sign
# 需要导入模块: from oscrypto import asymmetric [as 别名]
# 或者: from oscrypto.asymmetric import rsa_pkcs1v15_sign [as 别名]
def test_rsa_sign(self):
original_data = b'This is data to sign'
private = asymmetric.load_private_key(os.path.join(fixtures_dir, 'keys/test.key'))
public = asymmetric.load_public_key(os.path.join(fixtures_dir, 'keys/test.crt'))
signature = asymmetric.rsa_pkcs1v15_sign(private, original_data, 'sha1')
self.assertIsInstance(signature, byte_cls)
asymmetric.rsa_pkcs1v15_verify(public, signature, original_data, 'sha1')
示例4: test_rsa_raw_sign
# 需要导入模块: from oscrypto import asymmetric [as 别名]
# 或者: from oscrypto.asymmetric import rsa_pkcs1v15_sign [as 别名]
def test_rsa_raw_sign(self):
original_data = b'This is data to sign!'
private = asymmetric.load_private_key(os.path.join(fixtures_dir, 'keys/test.key'))
public = asymmetric.load_public_key(os.path.join(fixtures_dir, 'keys/test.crt'))
signature = asymmetric.rsa_pkcs1v15_sign(private, original_data, 'raw')
self.assertIsInstance(signature, byte_cls)
asymmetric.rsa_pkcs1v15_verify(public, signature, original_data, 'raw')