本文整理汇总了Python中oscrypto.asymmetric.rsa_pkcs1v15_verify方法的典型用法代码示例。如果您正苦于以下问题:Python asymmetric.rsa_pkcs1v15_verify方法的具体用法?Python asymmetric.rsa_pkcs1v15_verify怎么用?Python asymmetric.rsa_pkcs1v15_verify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oscrypto.asymmetric
的用法示例。
在下文中一共展示了asymmetric.rsa_pkcs1v15_verify方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rsa_generate
# 需要导入模块: from oscrypto import asymmetric [as 别名]
# 或者: from oscrypto.asymmetric import rsa_pkcs1v15_verify [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: test_rsa_verify
# 需要导入模块: from oscrypto import asymmetric [as 别名]
# 或者: from oscrypto.asymmetric import rsa_pkcs1v15_verify [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')
示例3: test_rsa_verify_key_size_mismatch
# 需要导入模块: from oscrypto import asymmetric [as 别名]
# 或者: from oscrypto.asymmetric import rsa_pkcs1v15_verify [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')
示例4: test_rsa_verify_fail
# 需要导入模块: from oscrypto import asymmetric [as 别名]
# 或者: from oscrypto.asymmetric import rsa_pkcs1v15_verify [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')
示例5: test_rsa_verify_fail_each_byte
# 需要导入模块: from oscrypto import asymmetric [as 别名]
# 或者: from oscrypto.asymmetric import rsa_pkcs1v15_verify [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')
示例6: test_rsa_raw_verify_fail
# 需要导入模块: from oscrypto import asymmetric [as 别名]
# 或者: from oscrypto.asymmetric import rsa_pkcs1v15_verify [as 别名]
def test_rsa_raw_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_raw'), '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', 'raw')
示例7: test_rsa_sign
# 需要导入模块: from oscrypto import asymmetric [as 别名]
# 或者: from oscrypto.asymmetric import rsa_pkcs1v15_verify [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')
示例8: test_rsa_raw_sign
# 需要导入模块: from oscrypto import asymmetric [as 别名]
# 或者: from oscrypto.asymmetric import rsa_pkcs1v15_verify [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')
示例9: _self_signed
# 需要导入模块: from oscrypto import asymmetric [as 别名]
# 或者: from oscrypto.asymmetric import rsa_pkcs1v15_verify [as 别名]
def _self_signed(cert):
"""
Determines if a certificate is self-signed
:param cert:
An asn1crypto.x509.Certificate object to check
:return:
A boolean - True if the certificate is self-signed, False otherwise
"""
self_signed = cert.self_signed
if self_signed == 'yes':
return True
if self_signed == 'no':
return False
# In the case of "maybe", we have to check the signature
signature_algo = cert['signature_algorithm'].signature_algo
hash_algo = cert['signature_algorithm'].hash_algo
if signature_algo == 'rsassa_pkcs1v15':
verify_func = asymmetric.rsa_pkcs1v15_verify
elif signature_algo == 'dsa':
verify_func = asymmetric.dsa_verify
elif signature_algo == 'ecdsa':
verify_func = asymmetric.ecdsa_verify
else:
raise PathValidationError(pretty_message(
'''
Unable to verify the signature of the certificate since it uses
the unsupported algorithm %s
''',
signature_algo
))
try:
key_object = asymmetric.load_certificate(cert)
verify_func(key_object, cert['signature_value'].native, cert['tbs_certificate'].dump(), hash_algo)
return True
except (oscrypto.errors.SignatureError):
return False
示例10: _verify_signature
# 需要导入模块: from oscrypto import asymmetric [as 别名]
# 或者: from oscrypto.asymmetric import rsa_pkcs1v15_verify [as 别名]
def _verify_signature(certificate_list, crl_issuer):
"""
Verifies the digital signature on an asn1crypto.crl.CertificateList object
:param certificate_list:
An asn1crypto.crl.CertificateList object
:param crl_issuer:
An asn1crypto.x509.Certificate object of the CRL issuer
:raises:
certvalidator.errors.CRLValidationError - when the signature is invalid or uses an unsupported algorithm
"""
signature_algo = certificate_list['signature_algorithm'].signature_algo
hash_algo = certificate_list['signature_algorithm'].hash_algo
if signature_algo == 'rsassa_pkcs1v15':
verify_func = asymmetric.rsa_pkcs1v15_verify
elif signature_algo == 'dsa':
verify_func = asymmetric.dsa_verify
elif signature_algo == 'ecdsa':
verify_func = asymmetric.ecdsa_verify
else:
raise CRLValidationError(pretty_message(
'''
Unable to verify the CertificateList since the signature uses the
unsupported algorithm %s
''',
signature_algo
))
try:
key_object = asymmetric.load_certificate(crl_issuer)
verify_func(
key_object,
certificate_list['signature'].native,
certificate_list['tbs_cert_list'].dump(),
hash_algo
)
except (oscrypto.errors.SignatureError):
raise CRLValidationError('Unable to verify the signature of the CertificateList')