def verify_sign(public_key, signature, message): """ verify signature Args: public_key:public key object signature:signature string raw_data:data string Returns: True: is valid signature;False: is invalid signature """ if isinstance(message, str): message = message.encode(encoding="utf-8") if isinstance(signature, str): signature = Encoder.hex_to_bytes(signature) try: public_key.verify(signature, message, ec.ECDSA(hashes.SHA256())) except Exception: logger.exception("verify signature error") return False else: return True
def get_public_key(public_key_string): pub_key_bytes = Encoder.hex_to_bytes(public_key_string) return ECCipher.create_public_key(pub_key_bytes)
def is_valid_signature(public_key_string, raw_data, signature): public_key_bytes = Encoder.hex_to_bytes(public_key_string) public_key = ECCipher.create_public_key(public_key_bytes) logger.debug("is_valid_verify_code public_key:" + public_key_string + ",raw_data:" + raw_data + ",signature:" + signature) return verify_signature(public_key, signature, raw_data)