开发者

Decode sha1 string to normal string

I am using following code to convert string to sha1 string but i am not able to find any solution for reverse of this i.e normal string from sha1 string.

+(NSString *)stringToSha1:(NSString *)str{
    const char *s = [str cStringUsingEncoding:NSASCIIStringEncoding];
    NSData *keyData = [NSData dataWithBytes:s length:strlen(s)];

    // This is the destination
    uint8_t digest[CC_SHA1_DIGEST_LENGTH] = {0};
    // This one function does an unkeyed SHA1 hash of your hash data
    CC_SHA1(keyData.bytes, keyData.length, digest);

    // Now convert to NSData structure to make it usable again
    NSData *out = [NSData dataWithBytes:digest length:CC_SHA1_DIGEST_LENGTH];
    // description converts to hex but puts <> around it and spaces every 4 bytes
    NSString *hash = [out description];
    hash = [hash stringByReplacingOccurrencesOfString:@" " withString:@""];
    hash = [hash stringByReplacingOccurrencesOfString:@"<" withString:@""];
    hash = [hash stringByReplacingOccurrencesOfString:@">" withString:@""];

  开发者_StackOverflow中文版  NSLog(@"Hash is %@ for string %@", hash, str);

    NSData *dtt = [hash dataUsingEncoding:NSUTF8StringEncoding];
    //dtt = [nsda]
    NSString *unhash = [dtt description];

    return hash;
}

plz help me to solve this issue.

Thanks in advance


SHA1 is a one-way hash: it cannot be "decoded".

Hashing is used to turn a value into another probably-unique value. For example, you can fingerprint files by computing their hashes. Then, for example, you can know that you've successfully downloaded the right gigabyte of data by computing its hash and comparing it to the hash you expect.

Passwords are often hashed: I can check if you've entered the right password without having a copy of your password: I hash the password when you set it, and store that. Then when you enter your password, if it hashes to the same value, it's the right password.


SHA-1 is a one-way hash algorithm, so there isn't an algorithm to go from a SHA-1 string to a normal string.


SHA1 digests are one way digests and original string cannot be retrieved back from the digest.


You can't decode it. But if you are too desperate, Brute-force it!


You can also use a rainbow table used for reversing cryptographic hash functions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜