Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get MD5 sum of a string using python?

Tags:

python

md5

flickr

In the Flickr API docs, you need to find the MD5 sum of a string to generate the [api_sig] value.

How does one go about generating an MD5 sum from a string?

Flickr's example:

string: 000005fab4534d05api_key9a0554259914a86fb9e7eb014e4e5d52permswrite

MD5 sum: a02506b31c1cd46c2e0b6380fb94eb3d

like image 443
super9 Avatar asked Mar 14 '11 10:03

super9


People also ask

Does MD5 hash Python?

Use the MD5 Algorithm in Python To obtain the hash value, use the digest() method, which returns a bytes object digest of the data fed to the hash object. Similar to the digest() method, you can also use hexdigest() , which returns a string object of the digest containing only hexadecimal digits.


2 Answers

You can do the following:

Python 2.x

import hashlib print hashlib.md5("whatever your string is").hexdigest() 

Python 3.x

import hashlib print(hashlib.md5("whatever your string is".encode('utf-8')).hexdigest()) 

However in this case you're probably better off using this helpful Python module for interacting with the Flickr API:

  • http://stuvel.eu/flickrapi

... which will deal with the authentication for you.

Official documentation of hashlib

like image 130
Mark Longair Avatar answered Sep 22 '22 21:09

Mark Longair


For Python 2.x, use python's hashlib

import hashlib m = hashlib.md5() m.update("000005fab4534d05api_key9a0554259914a86fb9e7eb014e4e5d52permswrite") print m.hexdigest() 

Output: a02506b31c1cd46c2e0b6380fb94eb3d

like image 40
Ikke Avatar answered Sep 22 '22 21:09

Ikke