mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-02 22:42:45 +08:00
47 lines
1.4 KiB
Objective-C
47 lines
1.4 KiB
Objective-C
//
|
|
// NSData+MD5.m
|
|
// RestKit
|
|
//
|
|
// Created by Jeff Arena on 4/4/11.
|
|
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
|
|
#import <CommonCrypto/CommonDigest.h>
|
|
#import "NSData+RKAdditions.h"
|
|
#import "RKFixCategoryBug.h"
|
|
|
|
RK_FIX_CATEGORY_BUG(NSData_RKAdditions)
|
|
|
|
@implementation NSData (RKAdditions)
|
|
|
|
- (NSString *)MD5
|
|
{
|
|
// Create byte array of unsigned chars
|
|
unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH];
|
|
|
|
// Create 16 byte MD5 hash value, store in buffer
|
|
CC_MD5(self.bytes, (CC_LONG)self.length, md5Buffer);
|
|
|
|
// Convert unsigned char buffer to NSString of hex values
|
|
NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH *2];
|
|
for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
|
|
[output appendFormat:@"%02x", md5Buffer[i]];
|
|
}
|
|
|
|
return output;
|
|
}
|
|
|
|
@end
|