HMAC vs simple MD5 Hash

HMAC is not susceptible to length extension attacks. md5(T + K) should be fine for most uses unless your adversary is motivated to tamper with your message and has very good computing power. As long as you control T, birthday attacks are not applicable and you only have brute-force attacks. But it is good to … Read more

How to use CC_MD5 method in swift language

This is what I came up with. It’s an extension to String. Don’t forget to add #import <CommonCrypto/CommonCrypto.h> to the ObjC-Swift bridging header that Xcode creates. extension String { var md5: String! { let str = self.cStringUsingEncoding(NSUTF8StringEncoding) let strLen = CC_LONG(self.lengthOfBytesUsingEncoding(NSUTF8StringEncoding)) let digestLen = Int(CC_MD5_DIGEST_LENGTH) let result = UnsafeMutablePointer<CUnsignedChar>.alloc(digestLen) CC_MD5(str!, strLen, result) let hash = … Read more

Getting ETags right

ETag is similar to the Last-Modified header. It’s a mechanism to determine change by the client. An ETag needs to be a unique value representing the state and specific format of a resource (a resource could have multiple formats that each need their own ETag). Not unique across the entire domain of resources, simply within … Read more

What are the chances that two messages have the same MD5 digest and the same SHA1 digest?

Assuming uniform spread in the range of MD5 and SHA-1 hashes for random strings (which isn’t the case), and assuming we’re only talking about two strings and not talking about a pool of strings (so we avoid birthday-paradox-type complexities): An MD5 hash is 128 bits wide, and SHA-1’s is 160. With the above assumptions, two … Read more

Check if string is an MD5 Hash

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. This function checks that: It contains only letters and digits (a-f, 0-9). It’s 32 characters long.

php: number only hash?

An MD5 or SHA1 hash in PHP returns a hexadecimal number, so all you need to do is convert bases. PHP has a function that can do this for you: $bignum = hexdec( md5(“test”) ); or $bignum = hexdec( sha1(“test”) ); PHP Manual for hexdec Since you want a limited size number, you could then … Read more

Google Drive MD5 checksum for files

edit: NB these instructions have changed slightly for the v3 API I’ve figured out a quick way to get the MD5 checksums of the files uploaded and decided to share it here, too. Log into your Google Drive account, then: Visit: https://developers.google.com/drive/v3/reference/files/list Scroll down to the Try it! section. Change “Authorize requests using OAuth 2.0” … Read more

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