Commits

Doug Hellmann committed f79270e

show a straight md5 checksum, too

  • Participants
  • Parent commits 2fbc465

Comments (0)

Files changed (1)

File hidden_stdlib/hmac_message_signing.py

 """Signing and verifying messages with hmac
 """
 
+import hashlib
 import hmac
 from cStringIO import StringIO
 import pickle
 digest_maker = hmac.new('shared-secret-value')
 digest_maker.update(encoded_message)
 signature = digest_maker.hexdigest()
+checksum = hashlib.md5(encoded_message).hexdigest()
+
+print 'Checksum          :', checksum
+print 'Outgoing signature:', signature
 
 # Simulate sending the message
 buffer = StringIO('%s\n%d\n%s' % (signature,
 digest_maker = hmac.new('shared-secret-value',
                         read_message)
 computed_signature = digest_maker.hexdigest()
+print 'Computed signature:', signature
 
 if computed_signature == read_signature:
-    print 'Valid message, processed'
+    print '\nValid message, processed'
     safe_message = pickle.loads(read_message)
     print 'Message:', safe_message
 else: