本文整理汇总了Python中rsa.VerificationError方法的典型用法代码示例。如果您正苦于以下问题:Python rsa.VerificationError方法的具体用法?Python rsa.VerificationError怎么用?Python rsa.VerificationError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rsa
的用法示例。
在下文中一共展示了rsa.VerificationError方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unpack_license_key
# 需要导入模块: import rsa [as 别名]
# 或者: from rsa import VerificationError [as 别名]
def unpack_license_key(key_str, pubkey_args):
"""
Decode a string of license key data produced by `pack_license_key`. In other
words, this function is the inverse of `pack_...` above:
data == unpack_license_key(pack_license_key(data, ...), ...)
If the given string is not a valid key, `InvalidKey` is raised.
The parameter `pubkey_args` is a dictionary containing values for the RSA
fields "n" and "e". It can be generated with fbs's command `init_licensing`.
"""
try:
result = json.loads(key_str)
except ValueError:
raise InvalidKey() from None
try:
signature = result.pop('key')
except KeyError:
raise InvalidKey() from None
try:
signature_bytes = b64decode(signature.encode('ascii'))
except ValueError:
raise InvalidKey() from None
try:
rsa.verify(_dumpb(result), signature_bytes, PublicKey(**pubkey_args))
except VerificationError:
raise InvalidKey() from None
return result
示例2: _validate_signature
# 需要导入模块: import rsa [as 别名]
# 或者: from rsa import VerificationError [as 别名]
def _validate_signature(self, receipt: str, signature: str) -> bool:
try:
sig = base64.standard_b64decode(signature)
return rsa.verify(receipt.encode(), sig, self.public_key)
except (rsa.VerificationError, TypeError, ValueError, BaseException):
return False
示例3: perform_operation
# 需要导入模块: import rsa [as 别名]
# 或者: from rsa import VerificationError [as 别名]
def perform_operation(self, indata, pub_key, cli_args):
"""Verifies files."""
signature_file = cli_args[1]
with open(signature_file, 'rb') as sigfile:
signature = sigfile.read()
try:
rsa.verify(indata, signature, pub_key)
except rsa.VerificationError:
raise SystemExit('Verification failed.')
print('Verification OK', file=sys.stderr)
示例4: perform_operation
# 需要导入模块: import rsa [as 别名]
# 或者: from rsa import VerificationError [as 别名]
def perform_operation(self, indata, pub_key, cli_args):
'''Decrypts files.'''
signature_file = cli_args[1]
with open(signature_file, 'rb') as sigfile:
signature = sigfile.read()
try:
rsa.verify(indata, signature, pub_key)
except rsa.VerificationError:
raise SystemExit('Verification failed.')
print('Verification OK', file=sys.stderr)
示例5: _validate_signature
# 需要导入模块: import rsa [as 别名]
# 或者: from rsa import VerificationError [as 别名]
def _validate_signature(self, receipt, signature):
try:
sig = base64.standard_b64decode(signature)
return rsa.verify(receipt.encode(), sig, self.public_key)
except (rsa.VerificationError, TypeError):
return False