美文网首页
iOS Md5 Sa1加密

iOS Md5 Sa1加密

作者: cb6a1e2768d1 | 来源:发表于2016-11-12 13:54 被阅读21次
    #import <CommonCrypto/CommonDigest.h>
    
    + (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;  
    
    }  
    
    + (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;  
    
    }  ```

    相关文章

      网友评论

          本文标题:iOS Md5 Sa1加密

          本文链接:https://www.haomeiwen.com/subject/yqdqpttx.html