Java calculate hex representation of a SHA-1 digest of a String
Using apache common codec library: DigestUtils.sha1Hex(“aff”) The result is 0c05aa56405c447e6678b7f3127febde5c3a9238 That’s it 🙂
Using apache common codec library: DigestUtils.sha1Hex(“aff”) The result is 0c05aa56405c447e6678b7f3127febde5c3a9238 That’s it 🙂
You can use the following command: git log –format=”%ae” HASH^! It works with git show as well. You need to include -s to suppress the diff. git show -s –format=”%ae” HASH
I’ve made some CMake modules that peer into a git repo for versioning and similar purposes – they’re all in my repository at https://github.com/rpavlik/cmake-modules The good thing about these functions is, they will force a re-configure (a rerun of cmake) before a build every time the HEAD commit changes. Unlike doing something just once with … Read more
Your Objective-C code (using a NSString category) can be directly translated to Swift (using a String extension). First you have to create a “bridging header” and add #import <CommonCrypto/CommonCrypto.h> Then: extension String { func sha1() -> String { let data = self.dataUsingEncoding(NSUTF8StringEncoding)! var digest = [UInt8](count:Int(CC_SHA1_DIGEST_LENGTH), repeatedValue: 0) CC_SHA1(data.bytes, CC_LONG(data.length), &digest) let output = NSMutableString(capacity: … Read more
Are the 160 bit hash values generated by SHA-1 large enough to ensure the fingerprint of every block is unique? Assuming random hash values with a uniform distribution, a collection of n different data blocks and a hash function that generates b bits, the probability p that there will be one or more collisions is … Read more
I got my Answer, it was quit simple. Open Terminal, Type command: keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android Press Enter: You will get the following info, and SHA1 can be seen there. ….. Certificate fingerprints: MD5: 79:F5:59:…………….FE:09:D1:EC SHA1: 33:57:0A:C9:………………:91:47:14:CD SHA256: 39:AA:23:88:D6:……………….33:DF:61:24:CB:17:47:EA:39:94:99 …….
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
What you describe is called a collision. Collisions necessarily exist, since SHA-1 accepts many more distinct messages as input that it can produce distinct outputs (SHA-1 may eat any string of bits up to 2^64 bits, but outputs only 160 bits; thus, at least one output value must pop up several times). This observation is … Read more
For those who want a “standard” text formatting of the hash, you can use something like the following: static string Hash(string input) { using (SHA1Managed sha1 = new SHA1Managed()) { var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(input)); var sb = new StringBuilder(hash.Length * 2); foreach (byte b in hash) { // can be “x2” if you want lowercase … Read more
The easiest method I use to convert byte to string is: myString := string(myBytes[:])