def Sign(self, msg): """ Return raw byte string of signature on the SHA-1 hash_id of the message. @param msg: message to be signed @type msg: string @return: string representation of long int signature over message @rtype: string """ emsa_encoded = util.MakeEmsaMessage(msg, self.size) return util.BigIntToBytes(self.key.sign(emsa_encoded, None)[0])
def Verify(self, msg, sig): """ Return True if the signature corresponds to the message. @param msg: message that has been signed @type msg: string @param sig: string representation of long int signature @type sig: string @return: True if signature is valid for the message hash. False otherwise. @rtype: boolean """ try: return self.key.verify(util.MakeEmsaMessage(msg, self.size), (util.BytesToLong(sig),)) except ValueError: # if sig is not a long, it's invalid return False