문자열을 sha1 문자열로 변환하는 데 다음 코드를 사용하고 있는데, sha1 문자열의이 일반 문자열 즉, 일반 문자열을 역으로 해석 할 수있는 솔루션을 찾을 수 없습니다.sha1 문자열을 일반 문자열로 디코드하십시오.
+(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이 문제를 해결하는 데 도움을줍니다. 사전
+1 - 이유 해시를 디코딩 할 수없는 이유는 "고유 한"비트 해싱은 결과 해시가 가능한 값의 범위보다 작은 경우 반드시 다 대일 프로세스입니다. 다 대일 알고리즘은 "this * might *가 원래의 값일 수 있습니다"라는 신뢰 수준으로 만 역전 될 수 있습니다. –