Decode sha1 string to regular string

I am using the following code to convert a string to a sha1 string, but I cannot find any solution to reverse convert this normal string from a 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:@""];

    NSLog(@"Hash is %@ for string %@", hash, str);

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

    return hash;
}

plz help me solve this problem.

Thanks in advance

+1
source share
4 answers

SHA-1 is a one-way hash algorithm, so the algorithm does not go from the SHA-1 line to the normal line.

+6
source

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

, , . , , . , , , , .

: , : . , , , .

+8

SHA1 collections are one-way digests, and the original string cannot be returned from the digest.

+1
source

You cannot decode it. But if you are too desperate, Brute-force it!

0
source

Source: https://habr.com/ru/post/1767959/


All Articles