How can I convert a String to an MD5 hash in iOS using Swift?

There are two steps: 1. Create md5 data from a string 2. Covert the md5 data to a hex string Swift 2.0: func md5(string string: String) -> String { var digest = [UInt8](count: Int(CC_MD5_DIGEST_LENGTH), repeatedValue: 0) if let data = string.dataUsingEncoding(NSUTF8StringEncoding) { CC_MD5(data.bytes, CC_LONG(data.length), &digest) } var digestHex = “” for index in 0..<Int(CC_MD5_DIGEST_LENGTH) { … Read more

Get the MD5 hash of big files in Python

You need to read the file in chunks of suitable size: def md5_for_file(f, block_size=2**20): md5 = hashlib.md5() while True: data = f.read(block_size) if not data: break md5.update(data) return md5.digest() Note: Make sure you open your file with the ‘rb’ to the open – otherwise you will get the wrong result. So to do the whole … Read more

Hashing a file in Python

TL;DR use buffers to not use tons of memory. We get to the crux of your problem, I believe, when we consider the memory implications of working with very large files. We don’t want this bad boy to churn through 2 gigs of ram for a 2 gigabyte file so, as pasztorpisti points out, we … Read more

Simple (non-secure) hash function for JavaScript? [duplicate]

I didn’t verify this myself, but you can look at this JavaScript implementation of Java’s String.hashCode() method. Seems reasonably short. With this prototype you can simply call .hashCode() on any string, e.g. “some string”.hashCode(), and receive a numerical hash code (more specifically, a Java equivalent) such as 1395333309. String.prototype.hashCode = function() { var hash = … Read more

Calculate a MD5 hash from a string

As per MSDN Create MD5: public static string CreateMD5(string input) { // Use input string to calculate MD5 hash using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create()) { byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input); byte[] hashBytes = md5.ComputeHash(inputBytes); return Convert.ToHexString(hashBytes); // .NET 5 + // Convert the byte array to hexadecimal string prior to .NET 5 // StringBuilder sb = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)