澳门新蒲京娱乐


找回Win8.1(windows server 2011 PRADO2)的双拼

win7系统IE任务栏如何不用选择列表直接弹出IE,Windows7常见问答汇总二

出现同样的hash值问题

iOS: [NSString hash]出现同样的hash值问题

iOS开发-MD5加密、SHA1加密,ios-md5sha1加密

问题原因:

At least there are special circumstances for which this unreliability
kicks in.

Comparing [a hash] and [b hash] of two different NSString is safe
when:

  • the strings’ length is shorter or equal to 96 characters.
  • [a length] is different to [b length].
  • the concatinated first, middle, and last 32 characters of a differ
    to the concatinated components of b.

    Otherwise every difference between the first and the middle 32
    chars, as well as every difference between the middle and the last
    32 characters, are not used while producing the [NSString hash]
    value.

    解决方法:

    For my case, the solution was pretty easy. I made use of a sha1
    hash, which produced
    a fingerprint from the whole string instead of pieces only. I got
    mine inspired by
    the SHA1 method of Saurabh Sharma

    lang:objc SHA1

    • (NSString *)sha1 { NSData *data = [self
      dataUsingEncoding:NSUTF8StringEncoding]; uint8t
      digest[CC
      SHA1DIGESTLENGTH];

      CC_SHA1(data.bytes, data.length, digest);

      NSMutableString *output = [NSMutableString
      stringWithCapacity:CCSHA1DIGEST_LENGTH * 2];

      for (int i = 0; i < CCSHA1DIGEST_LENGTH; i++) { [output
      appendFormat:@”%02x”, digest[i]]; }

      return output; }

    The SHA1 was for the name of a cached file, generated by giving the
    complete URL of the resource to be cached. Works perfect. I already
    filed a pull request for

    PS:

    How to get md5 and SHA1 in objective c (iOS sdk)

    Calculating the md5 and sha1 hash in iOS sdk is pretty simple –

    Step 1 – The very first thing you need to do is import
    CommonCrypto’s CommonDigest.h

    #import 
    

    Step 2 – Here is the real code for calculating SHA1 and MD5 hash –

    SHA1 –

    -(NSString*) sha1:(NSString*)input
    {
     const char *cstr = [input cStringUsingEncoding:NSUTF8StringEncoding];
     NSData *data = [NSData dataWithBytes:cstr length:input.length];
    
     uint8_t digest[CC_SHA1_DIGEST_LENGTH];
    
     CC_SHA1(data.bytes, 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;
    
    }
    

    MD5 –

    - (NSString *) md5:(NSString *) input
    {
     const char *cStr = [input UTF8String];
     unsigned char digest[16];
     CC_MD5( cStr, strlen(cStr), digest ); // This is the md5 call
    
     NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    
     for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
     [output appendFormat:@"%02x", digest[i]];
    
     return  output;
    
    }
    

    Hope it will help someone!!

http://www.bkjia.com/IOSjc/956627.htmlwww.bkjia.comtruehttp://www.bkjia.com/IOSjc/956627.htmlTechArticleiOS: \[NSString hash\]出现同样的hash值问题
问题原因: At least there are special circumstances for which this
unreliability kicks in. Comparing \[a hash\] and \[b hash\]
of...

1.MD5加密

///MD5加密

+ (NSString *)md5:(NSString *)inputString{

    const char *cStr = [inputString UTF8String];

    unsigned char digest[CC_MD5_DIGEST_LENGTH];

    CC_MD5( cStr, (int)strlen(cStr), digest );

    NSMutableString *output = [NSMutableString
stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];

    for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)

        [output appendFormat:@”%02x”, digest[澳门新蒲京娱乐 ,i]];

    ///转变成大写

    NSString *putString = [output uppercaseString];

    return  putString; 

}

相关文章

No Comments, Be The First!
近期评论
    功能
    网站地图xml地图