Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an md5 hash of a string in RubyMotion

Tags:

ios

rubymotion

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?

like image 566
silasjmatson Avatar asked Aug 30 '12 18:08

silasjmatson


People also ask

How do you calculate MD5 hash of a string?

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.

How do I create an MD5 hash?

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.

How do I check if a string is MD5?

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.

How do I get MD5 terminal?

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.


1 Answers

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))
like image 180
Dylan Markow Avatar answered Oct 27 '22 15:10

Dylan Markow