sha1

How to SHA1 hash a string in Android?

时光毁灭记忆、已成空白 提交于 2019-11-26 04:38:08
问题 In Objective C I\'ve been using the following code to hash a string: -(NSString *) sha1:(NSString*)stringToHash { const char *cStr = [stringToHash UTF8String]; unsigned char result[20]; CC_SHA1( cStr, strlen(cStr), result ); return [NSString stringWithFormat:@\"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\", result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7], result[8], result[9], result[10], result[11], result[12],

How to assign a Git SHA1's to a file without Git?

不打扰是莪最后的温柔 提交于 2019-11-26 04:32:24
问题 As I understand it when Git assigns a SHA1 hash to a file this SHA1 is unique to the file based on its contents. As a result if a file moves from one repository to another the SHA1 for the file remains the same as its contents have not changed. How does Git calculate the SHA1 digest? Does it do it on the full uncompressed file contents? I would like to emulate assigning SHA1\'s outside of Git. 回答1: This is how Git calculates the SHA1 for a file (or, in Git terms, a "blob"): sha1("blob " +

How to hash NSString with SHA1 in Swift?

穿精又带淫゛_ 提交于 2019-11-26 04:11:47
问题 In objective-c it looks like this: #include <sys/xattr.h> @implementation NSString (reverse) -(NSString*)sha1 { NSData *data = [self dataUsingEncoding:NSUTF8StringEncoding]; uint8_t digest[CC_SHA1_DIGEST_LENGTH]; CC_SHA1(data.bytes, (int)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; } @end I need something like this with

Objective-C sample code for HMAC-SHA1 [closed]

拈花ヽ惹草 提交于 2019-11-26 03:47:55
问题 I need to generate HMAC-SHA1 in Objective C. But i didnt find anything that works. I tried with CommonCrypto, using CCHMAC, but didnt works. I need to generate a hmac and after generate HOTP number. Somebody have any example code in Objective C or C? 回答1: Here's how you generate an HMAC using SHA-256: NSString *key; NSString *data; const char *cKey = [key cStringUsingEncoding:NSASCIIStringEncoding]; const char *cData = [data cStringUsingEncoding:NSASCIIStringEncoding]; unsigned char cHMAC[CC

Java String to SHA1

别来无恙 提交于 2019-11-26 03:29:39
问题 I\'m trying to make a simple String to SHA1 converter in Java and this is what I\'ve got... public static String toSHA1(byte[] convertme) { MessageDigest md = null; try { md = MessageDigest.getInstance(\"SHA-1\"); } catch(NoSuchAlgorithmException e) { e.printStackTrace(); } return new String(md.digest(convertme)); } When I pass it toSHA1(\"password\".getBytes()) , I get [�a�ɹ??�%l�3~��. I know it\'s probably a simple encoding fix like UTF-8, but could someone tell me what I should do to get

How can I get the MD5 fingerprint from Java&#39;s keytool, not only SHA-1?

匆匆过客 提交于 2019-11-26 03:05:01
问题 As I want to use Google maps in my application, I need the debug certificates\' MD5 fingerprint. I tried following.: (Here I copied the debug.keystore file from C:\\Documents and Settings\\Administrator.android in bin folder) C:\\Program Files\\Java\\jdk1.7.0\\bin>keytool -list -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android But got the following results: androiddebugkey, May 27, 2011, PrivateKeyEntry,Certificate fingerprint (SHA1): \"some code\" However

How does the newly found SHA-1 collision affect Git?

不问归期 提交于 2019-11-26 01:54:58
问题 Recently a team of researchers generated two files with the same SHA-1 hash (https://shattered.it/). Since Git uses this hash for its internal storage, how far does this kind of attack influence Git? 回答1: Edit, late December 2017: Git version 2.16 is gradually acquiring internal interfaces to allow for different hashes. There is a long way to go yet. The short (but unsatisfying) answer is that the example files are not a problem for Git—but two other (carefully calculated) files could be. I

Probability of SHA1 collisions

人盡茶涼 提交于 2019-11-26 01:54:21
问题 Given a set of 100 different strings of equal length, how can you quantify the probability that a SHA1 digest collision for the strings is unlikely... ? 回答1: 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 bounded by the number of

Is SHA-1 secure for password storage?

本小妞迷上赌 提交于 2019-11-26 01:04:35
问题 Conclusion: SHA-1 is as safe as anything against preimage attacks, however it is easy to compute, which means it is easier to mount a bruteforce or dictionary attack. (The same is true for successors like SHA-256.) Depending on the circumstances, a hash function which was designed to be computationally expensive (such as bcrypt) might be a better choice. Some people throw around remarks like \"SHA-1 is broken\" a lot, so I\'m trying to understand what exactly that means. Let\'s assume I have

Is SHA-1 secure for password storage?

自闭症网瘾萝莉.ら 提交于 2019-11-25 23:34:36
Conclusion: SHA-1 is as safe as anything against preimage attacks, however it is easy to compute, which means it is easier to mount a bruteforce or dictionary attack. (The same is true for successors like SHA-256.) Depending on the circumstances, a hash function which was designed to be computationally expensive (such as bcrypt) might be a better choice. Some people throw around remarks like "SHA-1 is broken" a lot, so I'm trying to understand what exactly that means. Let's assume I have a database of SHA-1 password hashes, and an attacker whith a state of the art SHA-1 breaking algorithm and