Current location - Quotes Website - Signature design - Please explain this signature algorithm, where str 1 and str2 are string variables. What is the logic of this algorithm?
Please explain this signature algorithm, where str 1 and str2 are string variables. What is the logic of this algorithm?
tr 1+' & amp;' Is the key and str2 is the encrypted message.

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()