Is it possible to reverse a SHA-1 hash?

No, you cannot reverse SHA-1, that is exactly why it is called a Secure Hash Algorithm. What you should definitely be doing though, is include the message that is being transmitted into the hash calculation. Otherwise a man-in-the-middle could intercept the message, and use the signature (which only contains the sender’s key and the timestamp) … Read more

Creating SHA1 Hash from NSString

I have this in a category on NSString (available at https://github.com/hypercrypt/NSString-Hashes): #import <CommonCrypto/CommonDigest.h> … – (NSString *)sha1 { NSData *data = [self dataUsingEncoding:NSUTF8StringEncoding]; uint8_t digest[CC_SHA1_DIGEST_LENGTH]; CC_SHA1(data.bytes, (CC_LONG)data.length, digest); NSMutableString *output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2]; for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) { [output appendFormat:@”%02x”, digest[i]]; } return output; } Starting with Xcode … Read more

Git – finding a filename from a SHA1

There’s no such direct mapping in git as the name of the file is part of the tree object that contains the file, not of the blob object that is the file’s contents. It’s not a usual operation to want to retrieve a file name from a SHA1 hash so perhaps you could expand on … 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

A Regex to match a SHA1

You can consider the SHA1 hashes to be completely random, so this reduces to a matter of probabilities. The probability that a given digit is not a number is 6/16, or 0.375. The probability that three SHA1 digits are all not numbers is 0.375 ** 3, or 0.0527 (5% ish). At six digits, this reduces … Read more

Check if my SSL Certificate is SHA1 or SHA2

Use the Linux Command Line Use the command line, as described in this related question: How do I check if my SSL Certificate is SHA1 or SHA2 on the commandline. Command Here’s the command. Replace www.yoursite.com:443 to fit your needs. Default SSL port is 443: openssl s_client -connect www.yoursite.com:443 < /dev/null 2>/dev/null \ | openssl … Read more

How to generate an HMAC in Java equivalent to a Python example?

HmacSHA1 seems to be the algorithm name you need: SecretKeySpec keySpec = new SecretKeySpec( “qnscAdgRlkIhAUPY44oiexBKtQbGY0orf7OV1I50”.getBytes(), “HmacSHA1”); Mac mac = Mac.getInstance(“HmacSHA1”); mac.init(keySpec); byte[] result = mac.doFinal(“foo”.getBytes()); BASE64Encoder encoder = new BASE64Encoder(); System.out.println(encoder.encode(result)); produces: +3h2gpjf4xcynjCGU5lbdMBwGOc= Note that I’ve used sun.misc.BASE64Encoder for a quick implementation here, but you should probably use something that doesn’t depend on the Sun … Read more

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