【问题标题】:iPhone/OS X LION: How to retrieve the decoded data from the CC_SHA256 encrypted data?iPhone/OS X LION:如何从 CC_SHA256 加密数据中检索解码数据?
【发布时间】:2012-04-16 12:57:14
【问题描述】:

我正在使用以下代码 (CC_SHA256) 对 NSString 输入进行编码。有人可以帮助我使用相同的逻辑以解码格式检索吗?

    -(NSString*) encodeAndGetHashInfo :(NSString *) inStringToHashIt
{
    NSDate *currentDate = [NSDate date];
    NSLog(@"currentDate %@",currentDate);


    NSTimeInterval currTimeMillsecs = ([currentDate timeIntervalSince1970] * 1000);
    NSString *strCurrTimeMilliSecs = [NSString stringWithFormat:@"%.0f", currTimeMillsecs]; 
    NSLog(@"strCurrTimeMilliSecs: %@", strCurrTimeMilliSecs);  //here we are getting millsec in  this way 1328962624994.734131
    //double currentTime=[strCurrTimeMilliSecs doubleValue];

    //Do hashing    
    NSString *withSalt= [NSString stringWithFormat:@"%@%@%@", strCurrTimeMilliSecs, inStringToHashIt,STATIC_HASH];

    NSLog(@"withSalt.%@",withSalt);

    NSString *inputStr = withSalt;

    unsigned char hashedChars[32];
    CC_SHA256([inputStr UTF8String],
              [inputStr lengthOfBytesUsingEncoding:NSUTF8StringEncoding], 
              hashedChars);

    NSData * hashedData = [NSData dataWithBytes:hashedChars length:32];
    NSLog (@"hashedData:%@",hashedData );
    NSString* hashPasswordResponse = NULL;
    hashPasswordResponse = [NSString stringWithFormat:@"%@", hashedData];       

    hashPasswordResponse = [hashPasswordResponse stringByReplacingOccurrencesOfString:@" " withString:@""]; 
    NSLog(@"hashPasswordResponse.......%@",hashPasswordResponse);//this string is 

    return hashPasswordResponse;
}

【问题讨论】:

    标签: iphone osx-lion


    【解决方案1】:

    你不能 SHA 是一种散列算法,更不用说被解码了。

    就像Jonathan Grynspan 说的那样,如果你可以解码 sha(任何版本),就会破坏这种算法的目的。

    【讨论】:

    • 是的,但是对于 Rainbowtables,它可以 可以获得一个可以创建相同哈希值的值,这就是为什么你应该总是添加盐 ;)跨度>
    • 不可能:肯定。由于 SHA-256 输出的长度始终相同,因此适用鸽巢原理。
    【解决方案2】:

    正如其他人所指出的,SHA-1 和 SHA-2 变体在设计上是单向哈希。如果您可以反转它们,则散列被破坏。哈希旨在检查数据完整性,而不是提供数据加密。

    如果您想要加密/解密而不是散列,您想要使用 CommonCrypto 的CCCryptor 例程之一。见:

    Any cocoa source code for AES encryption decryption?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-21
      • 1970-01-01
      • 1970-01-01
      • 2015-12-01
      • 2015-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多