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

How do I do a SHA1 File Checksum in C#?

using (FileStream fs = new FileStream(@”C:\file\location”, FileMode.Open)) using (BufferedStream bs = new BufferedStream(fs)) { using (SHA1Managed sha1 = new SHA1Managed()) { byte[] hash = sha1.ComputeHash(bs); StringBuilder formatted = new StringBuilder(2 * hash.Length); foreach (byte b in hash) { formatted.AppendFormat(“{0:X2}”, b); } } } formatted contains the string representation of the SHA-1 hash. Also, by using … Read more

Password hash function for Excel VBA

Here’s a module for calculating SHA1 hashes that is usable for Excel formulas eg. ‘=SHA1HASH(“test”)’. To use it, make a new module called ‘module_sha1’ and copy and paste it all in. This is based on some VBA code from http://vb.wikia.com/wiki/SHA-1.bas, with changes to support passing it a string, and executable from formulas in Excel cells. … Read more

Hash collision in git

Picking atoms on 10 Moons An SHA-1 hash is a 40 hex character string… that’s 4 bits per character times 40… 160 bits. Now we know 10 bits is approximately 1000 (1024 to be exact) meaning that there are 1 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 … Read more

How to SHA1 hash a string in Android?

You don’t need andorid for this. You can just do it in simple java. Have you tried a simple java example and see if this returns the right sha1. import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class AeSimpleSHA1 { private static String convertToHex(byte[] data) { StringBuilder buf = new StringBuilder(); for (byte b : data) … Read more

How does Git compute file hashes?

Git prefixes the object with “blob “, followed by the length (as a human-readable integer), followed by a NUL character $ echo -e ‘blob 14\0Hello, World!’ | shasum 8ab686eafeb1f44702738c8b0f24f2567c36da6d Source: http://alblue.bandlem.com/2011/08/git-tip-of-week-objects.html