Before sending data, HMAC encryption algorithm "hashes" the data block and the public key agreed by both parties to generate something called "digest" and attach it to the data block to be sent. When the data and digest arrive at the destination, another checksum is generated by using HMAC encryption algorithm. If the two numbers match, then the data has not been tampered with.
You can download the installation package of hmac from pypi of python official website, which contains the source code of hmac.
The following is a simple C/S program, signed by hmac.
#? Clients? (Signs? That? Data)
Import? xmlrpclib、hmac、hashlib
Keys? =? "My Secret"
Server? =? xmlrpclib。 server proxy(" http://localhost:8888 ")
Name? =? Homer's epic
Signature? =? Hmac.new (key, name) hexdigest()
Print? Server.sayHello (signature, name)
#? Server? (verification? That? Signature)
Import? SimpleXMLRPCServer、hmac、hashlib
Keys? =? "My Secret"
Class? My category:
def? SayHello (self, signature,? Name):
What if? Hmac.new (key, name) hexdigest()? ! =? Signature:
Return? "Wrong? Signature? ! ? You are. Answer? Hacker? ! "
Otherwise:
Return? U "Hello, %s? ! "? %? name
Server _ object? =? MyClass()
Server? =? SimpleXMLRPCServer。 SimpleXMLRPCServer((“localhost”,? 8888))#? (2)
server . register _ instance(server _ object)#? (3)
Print? "listen? Open? Port? 8888"
server.serve_forever()