I have an email and want to pull the corresponding image from gravatar.com
With ruby, it's easy:
require 'Digest/md5'
Digest::MD5.hexdigest("my string")
Since there is no require
method in RubyMotion, how do I generate the hash from the email?
You can use md5sum command to compute and check MD5 message digest. This is a default tool on most modern Linux distributions. It generate a md5 hash for given string or words or filenames.
An MD5 hash is created by taking a string of an any length and encoding it into a 128-bit fingerprint. Encoding the same string using the MD5 algorithm will always result in the same 128-bit hash output.
You can check using the following function: function isValidMd5($md5 ='') { return preg_match('/^[a-f0-9]{32}$/', $md5); } echo isValidMd5('5d41402abc4b2a76b9719d911017c592'); The MD5 (Message-digest algorithm) Hash is typically expressed in text format as a 32 digit hexadecimal number.
Open a terminal window. Type the following command: md5sum [type file name with extension here] [path of the file] -- NOTE: You can also drag the file to the terminal window instead of typing the full path. Hit the Enter key. You'll see the MD5 sum of the file.
One possibility is using the "NSData+MD5" cocoapod. Install it by adding this to your Rakefile (make sure you have require 'motion-cocoapods'
up top):
app.pods do
pod 'NSData+MD5Digest'
end
Then you can use it like this:
digest = NSData.MD5HexDigest("my string".dataUsingEncoding(NSUTF8StringEncoding))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With