本文整理匯總了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