update ARC version

This commit is contained in:
Kelp 2012-05-15 21:50:57 +08:00
parent 2d7cd4f038
commit aa3ba0229b
8 changed files with 143 additions and 25 deletions

View File

@ -337,6 +337,7 @@
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)"; ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu99;
@ -362,6 +363,7 @@
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)"; ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES; COPY_PHASE_STRIP = YES;
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu99;

View File

@ -1,9 +1,16 @@
// /*
// CocoaSecurity.h CocoaSecurity 1.0.1
//
// Created by Kelp on 12/5/12. Created by Kelp on 12/5/12.
// Copyright (c) 2012 Kelp http://kelp.phate.org/ Copyright (c) 2012 Kelp http://kelp.phate.org/
// MIT License
CocoaSecurity is core. It provides AES encrypt, AES decrypt, Hash(MD5, HmacMD5, SHA1~SHA512, HmacSHA1~HmacSHA512) messages.
1.0.1 2012-05-15
update ARC version
*/
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <Foundation/NSException.h> #import <Foundation/NSException.h>

View File

@ -3,6 +3,7 @@
// //
// Created by Kelp on 12/5/12. // Created by Kelp on 12/5/12.
// Copyright (c) 2012 Kelp http://kelp.phate.org/ // Copyright (c) 2012 Kelp http://kelp.phate.org/
// MIT License
// //
#import "CocoaSecurity.h" #import "CocoaSecurity.h"
@ -26,7 +27,9 @@
CocoaSecurityDecoder *decoder = [[CocoaSecurityDecoder alloc] init]; CocoaSecurityDecoder *decoder = [[CocoaSecurityDecoder alloc] init];
NSData *aesKey = [decoder hex:key]; NSData *aesKey = [decoder hex:key];
NSData *aesIv = [decoder hex:iv]; NSData *aesIv = [decoder hex:iv];
#if !__has_feature(objc_arc)
[decoder release]; [decoder release];
#endif
return [self aesEncrypt:data key:aesKey iv:aesIv]; return [self aesEncrypt:data key:aesKey iv:aesIv];
} }
@ -64,9 +67,13 @@
[data length], [data length],
buffer, buffer,
bufferSize, bufferSize,
&encryptedSize); &encryptedSize);
if (cryptStatus == kCCSuccess) { if (cryptStatus == kCCSuccess) {
#if __has_feature(objc_arc)
CocoaSecurityResult *result = [[CocoaSecurityResult alloc] initWithBytes:buffer length:encryptedSize];
#else
CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:buffer length:encryptedSize] autorelease]; CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:buffer length:encryptedSize] autorelease];
#endif
free(buffer); free(buffer);
return result; return result;
@ -94,13 +101,19 @@
CocoaSecurityDecoder *decoder = [[CocoaSecurityDecoder alloc] init]; CocoaSecurityDecoder *decoder = [[CocoaSecurityDecoder alloc] init];
NSData *aesKey = [decoder hex:key]; NSData *aesKey = [decoder hex:key];
NSData *aesIv = [decoder hex:iv]; NSData *aesIv = [decoder hex:iv];
#if !__has_feature(objc_arc)
[decoder release]; [decoder release];
#endif
return [self aesDecryptWithBase64:data key:aesKey iv:aesIv]; return [self aesDecryptWithBase64:data key:aesKey iv:aesIv];
} }
- (CocoaSecurityResult *)aesDecryptWithBase64:(NSString *)data key:(NSData *)key iv:(NSData *)iv - (CocoaSecurityResult *)aesDecryptWithBase64:(NSString *)data key:(NSData *)key iv:(NSData *)iv
{ {
#if __has_feature(objc_arc)
CocoaSecurityDecoder *decoder = [[CocoaSecurityDecoder alloc] init];
#else
CocoaSecurityDecoder *decoder = [[[CocoaSecurityDecoder alloc] init] autorelease]; CocoaSecurityDecoder *decoder = [[[CocoaSecurityDecoder alloc] init] autorelease];
#endif
return [self aesDecryptWithData:[decoder base64:data] key:key iv:iv]; return [self aesDecryptWithData:[decoder base64:data] key:key iv:iv];
} }
@ -134,9 +147,13 @@
[data length], [data length],
buffer, buffer,
bufferSize, bufferSize,
&encryptedSize); &encryptedSize);
if (cryptStatus == kCCSuccess) { if (cryptStatus == kCCSuccess) {
#if __has_feature(objc_arc)
CocoaSecurityResult *result = [[CocoaSecurityResult alloc] initWithBytes:buffer length:encryptedSize];
#else
CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:buffer length:encryptedSize] autorelease]; CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:buffer length:encryptedSize] autorelease];
#endif
free(buffer); free(buffer);
return result; return result;
@ -160,7 +177,11 @@
digest = malloc(CC_MD5_DIGEST_LENGTH); digest = malloc(CC_MD5_DIGEST_LENGTH);
CC_MD5([hashData bytes], [hashData length], digest); CC_MD5([hashData bytes], [hashData length], digest);
#if __has_feature(objc_arc)
CocoaSecurityResult *result = [[CocoaSecurityResult alloc] initWithBytes:digest length:CC_MD5_DIGEST_LENGTH];
#else
CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_MD5_DIGEST_LENGTH] autorelease]; CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_MD5_DIGEST_LENGTH] autorelease];
#endif
free(digest); free(digest);
return result; return result;
@ -177,7 +198,11 @@
const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding]; const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding];
CCHmac(kCCHmacAlgMD5, cKey, strlen(cKey), [hashData bytes], [hashData length], digest); CCHmac(kCCHmacAlgMD5, cKey, strlen(cKey), [hashData bytes], [hashData length], digest);
#if __has_feature(objc_arc)
CocoaSecurityResult *result = [[CocoaSecurityResult alloc] initWithBytes:digest length:CC_MD5_DIGEST_LENGTH];
#else
CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_MD5_DIGEST_LENGTH] autorelease]; CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_MD5_DIGEST_LENGTH] autorelease];
#endif
free(digest); free(digest);
cKey = nil; cKey = nil;
@ -195,7 +220,11 @@
digest = malloc(CC_SHA1_DIGEST_LENGTH); digest = malloc(CC_SHA1_DIGEST_LENGTH);
CC_SHA1([hashData bytes], [hashData length], digest); CC_SHA1([hashData bytes], [hashData length], digest);
#if __has_feature(objc_arc)
CocoaSecurityResult *result = [[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA1_DIGEST_LENGTH];
#else
CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA1_DIGEST_LENGTH] autorelease]; CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA1_DIGEST_LENGTH] autorelease];
#endif
free(digest); free(digest);
return result; return result;
@ -211,7 +240,11 @@
digest = malloc(CC_SHA224_DIGEST_LENGTH); digest = malloc(CC_SHA224_DIGEST_LENGTH);
CC_SHA224([hashData bytes], [hashData length], digest); CC_SHA224([hashData bytes], [hashData length], digest);
#if __has_feature(objc_arc)
CocoaSecurityResult *result = [[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA224_DIGEST_LENGTH];
#else
CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA224_DIGEST_LENGTH] autorelease]; CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA224_DIGEST_LENGTH] autorelease];
#endif
free(digest); free(digest);
return result; return result;
@ -227,7 +260,11 @@
digest = malloc(CC_SHA256_DIGEST_LENGTH); digest = malloc(CC_SHA256_DIGEST_LENGTH);
CC_SHA256([hashData bytes], [hashData length], digest); CC_SHA256([hashData bytes], [hashData length], digest);
#if __has_feature(objc_arc)
CocoaSecurityResult *result = [[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA256_DIGEST_LENGTH];
#else
CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA256_DIGEST_LENGTH] autorelease]; CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA256_DIGEST_LENGTH] autorelease];
#endif
free(digest); free(digest);
return result; return result;
@ -243,7 +280,11 @@
digest = malloc(CC_SHA384_DIGEST_LENGTH); digest = malloc(CC_SHA384_DIGEST_LENGTH);
CC_SHA384([hashData bytes], [hashData length], digest); CC_SHA384([hashData bytes], [hashData length], digest);
#if __has_feature(objc_arc)
CocoaSecurityResult *result = [[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA384_DIGEST_LENGTH];
#else
CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA384_DIGEST_LENGTH] autorelease]; CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA384_DIGEST_LENGTH] autorelease];
#endif
free(digest); free(digest);
return result; return result;
@ -259,7 +300,11 @@
digest = malloc(CC_SHA512_DIGEST_LENGTH); digest = malloc(CC_SHA512_DIGEST_LENGTH);
CC_SHA512([hashData bytes], [hashData length], digest); CC_SHA512([hashData bytes], [hashData length], digest);
#if __has_feature(objc_arc)
CocoaSecurityResult *result = [[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA512_DIGEST_LENGTH];
#else
CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA512_DIGEST_LENGTH] autorelease]; CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA512_DIGEST_LENGTH] autorelease];
#endif
free(digest); free(digest);
return result; return result;
@ -277,7 +322,11 @@
const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding]; const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding];
CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), [hashData bytes], [hashData length], digest); CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), [hashData bytes], [hashData length], digest);
#if __has_feature(objc_arc)
CocoaSecurityResult *result = [[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA1_DIGEST_LENGTH];
#else
CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA1_DIGEST_LENGTH] autorelease]; CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA1_DIGEST_LENGTH] autorelease];
#endif
free(digest); free(digest);
cKey = nil; cKey = nil;
@ -295,7 +344,11 @@
const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding]; const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding];
CCHmac(kCCHmacAlgSHA224, cKey, strlen(cKey), [hashData bytes], [hashData length], digest); CCHmac(kCCHmacAlgSHA224, cKey, strlen(cKey), [hashData bytes], [hashData length], digest);
#if __has_feature(objc_arc)
CocoaSecurityResult *result = [[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA224_DIGEST_LENGTH];
#else
CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA224_DIGEST_LENGTH] autorelease]; CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA224_DIGEST_LENGTH] autorelease];
#endif
free(digest); free(digest);
cKey = nil; cKey = nil;
@ -313,7 +366,11 @@
const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding]; const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding];
CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), [hashData bytes], [hashData length], digest); CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), [hashData bytes], [hashData length], digest);
#if __has_feature(objc_arc)
CocoaSecurityResult *result = [[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA256_DIGEST_LENGTH];
#else
CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA256_DIGEST_LENGTH] autorelease]; CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA256_DIGEST_LENGTH] autorelease];
#endif
free(digest); free(digest);
cKey = nil; cKey = nil;
@ -331,7 +388,11 @@
const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding]; const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding];
CCHmac(kCCHmacAlgSHA384, cKey, strlen(cKey), [hashData bytes], [hashData length], digest); CCHmac(kCCHmacAlgSHA384, cKey, strlen(cKey), [hashData bytes], [hashData length], digest);
#if __has_feature(objc_arc)
CocoaSecurityResult *result = [[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA384_DIGEST_LENGTH];
#else
CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA384_DIGEST_LENGTH] autorelease]; CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA384_DIGEST_LENGTH] autorelease];
#endif
free(digest); free(digest);
cKey = nil; cKey = nil;
@ -349,7 +410,11 @@
const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding]; const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding];
CCHmac(kCCHmacAlgSHA512, cKey, strlen(cKey), [hashData bytes], [hashData length], digest); CCHmac(kCCHmacAlgSHA512, cKey, strlen(cKey), [hashData bytes], [hashData length], digest);
#if __has_feature(objc_arc)
CocoaSecurityResult *result = [[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA512_DIGEST_LENGTH];
#else
CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA512_DIGEST_LENGTH] autorelease]; CocoaSecurityResult *result = [[[CocoaSecurityResult alloc] initWithBytes:digest length:CC_SHA512_DIGEST_LENGTH] autorelease];
#endif
free(digest); free(digest);
cKey = nil; cKey = nil;
@ -376,7 +441,11 @@
// convert CocoaSecurityResult to UTF8 string // convert CocoaSecurityResult to UTF8 string
- (NSString *)utf8String - (NSString *)utf8String
{ {
#if __has_feature(objc_arc)
NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
#else
NSString *result = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]; NSString *result = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
#endif
return result; return result;
} }
@ -385,13 +454,21 @@
// convert CocoaSecurityResult to HEX string // convert CocoaSecurityResult to HEX string
- (NSString *)hex - (NSString *)hex
{ {
#if __has_feature(objc_arc)
CocoaSecurityEncoder *encoder = [[CocoaSecurityEncoder alloc] init];
#else
CocoaSecurityEncoder *encoder = [[[CocoaSecurityEncoder alloc] init] autorelease]; CocoaSecurityEncoder *encoder = [[[CocoaSecurityEncoder alloc] init] autorelease];
#endif
return [encoder hex:data useLower:false]; return [encoder hex:data useLower:false];
} }
- (NSString *)hexLower - (NSString *)hexLower
{ {
#if __has_feature(objc_arc)
CocoaSecurityEncoder *encoder = [[CocoaSecurityEncoder alloc] init];
#else
CocoaSecurityEncoder *encoder = [[[CocoaSecurityEncoder alloc] init] autorelease]; CocoaSecurityEncoder *encoder = [[[CocoaSecurityEncoder alloc] init] autorelease];
#endif
return [encoder hex:data useLower:true]; return [encoder hex:data useLower:true];
} }
@ -400,7 +477,11 @@
// convert CocoaSecurityResult to Base64 string // convert CocoaSecurityResult to Base64 string
- (NSString *)base64 - (NSString *)base64
{ {
#if __has_feature(objc_arc)
CocoaSecurityEncoder *encoder = [[CocoaSecurityEncoder alloc] init];
#else
CocoaSecurityEncoder *encoder = [[[CocoaSecurityEncoder alloc] init] autorelease]; CocoaSecurityEncoder *encoder = [[[CocoaSecurityEncoder alloc] init] autorelease];
#endif
return [encoder base64:data]; return [encoder base64:data];
} }
@ -416,7 +497,11 @@
{ {
// base on GTMBase64 // base on GTMBase64
NSString *result = [[NSString alloc] initWithData:[GTMBase64 encodeData:data] encoding:NSUTF8StringEncoding]; NSString *result = [[NSString alloc] initWithData:[GTMBase64 encodeData:data] encoding:NSUTF8StringEncoding];
#if __has_feature(objc_arc)
return result;
#else
return [result autorelease]; return [result autorelease];
#endif
} }
// convert NSData to hex string // convert NSData to hex string
@ -464,7 +549,11 @@
{ {
// base on GTMBase64 // base on GTMBase64
NSData *result = [[NSData alloc] initWithData:[GTMBase64 decodeString:data]]; NSData *result = [[NSData alloc] initWithData:[GTMBase64 decodeString:data]];
#if __has_feature(objc_arc)
return result;
#else
return [result autorelease]; return [result autorelease];
#endif
} }
- (NSData *)hex: (NSString *)data - (NSData *)hex: (NSString *)data

View File

@ -283,8 +283,13 @@ GTM_INLINE NSUInteger GuessDecodedLength(NSUInteger srcLen) {
charset:kBase64EncodeChars charset:kBase64EncodeChars
padded:YES]; padded:YES];
if (converted) { if (converted) {
result = [[[NSString alloc] initWithData:converted #if __has_feature(objc_arc)
result = [[NSString alloc] initWithData:converted
encoding:NSASCIIStringEncoding];
#else
result = [[[NSString alloc] initWithData:converted
encoding:NSASCIIStringEncoding] autorelease]; encoding:NSASCIIStringEncoding] autorelease];
#endif
} }
return result; return result;
} }
@ -296,8 +301,13 @@ GTM_INLINE NSUInteger GuessDecodedLength(NSUInteger srcLen) {
charset:kBase64EncodeChars charset:kBase64EncodeChars
padded:YES]; padded:YES];
if (converted) { if (converted) {
result = [[[NSString alloc] initWithData:converted #if __has_feature(objc_arc)
result = [[NSString alloc] initWithData:converted
encoding:NSASCIIStringEncoding];
#else
result = [[[NSString alloc] initWithData:converted
encoding:NSASCIIStringEncoding] autorelease]; encoding:NSASCIIStringEncoding] autorelease];
#endif
} }
return result; return result;
} }
@ -362,8 +372,13 @@ GTM_INLINE NSUInteger GuessDecodedLength(NSUInteger srcLen) {
charset:kWebSafeBase64EncodeChars charset:kWebSafeBase64EncodeChars
padded:padded]; padded:padded];
if (converted) { if (converted) {
result = [[[NSString alloc] initWithData:converted #if __has_feature(objc_arc)
result = [[NSString alloc] initWithData:converted
encoding:NSASCIIStringEncoding];
#else
result = [[[NSString alloc] initWithData:converted
encoding:NSASCIIStringEncoding] autorelease]; encoding:NSASCIIStringEncoding] autorelease];
#endif
} }
return result; return result;
} }
@ -377,8 +392,13 @@ GTM_INLINE NSUInteger GuessDecodedLength(NSUInteger srcLen) {
charset:kWebSafeBase64EncodeChars charset:kWebSafeBase64EncodeChars
padded:padded]; padded:padded];
if (converted) { if (converted) {
result = [[[NSString alloc] initWithData:converted #if __has_feature(objc_arc)
result = [[NSString alloc] initWithData:converted
encoding:NSASCIIStringEncoding];
#else
result = [[[NSString alloc] initWithData:converted
encoding:NSASCIIStringEncoding] autorelease]; encoding:NSASCIIStringEncoding] autorelease];
#endif
} }
return result; return result;
} }

View File

@ -26,8 +26,8 @@
- (void)testEncodeDecode - (void)testEncodeDecode
{ {
CocoaSecurityDecoder *decoder = [[[CocoaSecurityDecoder alloc] init] autorelease]; CocoaSecurityDecoder *decoder = [[CocoaSecurityDecoder alloc] init];
CocoaSecurityEncoder *encoder = [[[CocoaSecurityEncoder alloc] init] autorelease]; CocoaSecurityEncoder *encoder = [[CocoaSecurityEncoder alloc] init];
// HEX // HEX
STAssertEqualObjects([encoder hex:[decoder hex:@"CC0A69779E15780ADAE46C45EB451A23"] useLower:false], STAssertEqualObjects([encoder hex:[decoder hex:@"CC0A69779E15780ADAE46C45EB451A23"] useLower:false],
@ -39,8 +39,8 @@
- (void)testAES - (void)testAES
{ {
CocoaSecurity *cs = [[[CocoaSecurity alloc] init] autorelease]; CocoaSecurity *cs = [[CocoaSecurity alloc] init];
CocoaSecurityDecoder *decoder = [[[CocoaSecurityDecoder alloc] init] autorelease]; CocoaSecurityDecoder *decoder = [[CocoaSecurityDecoder alloc] init];
// AES128 // AES128
CocoaSecurityResult *aes128 = [cs aesEncryptWithData:[@"kelp" dataUsingEncoding:NSUTF8StringEncoding] CocoaSecurityResult *aes128 = [cs aesEncryptWithData:[@"kelp" dataUsingEncoding:NSUTF8StringEncoding]
@ -78,7 +78,7 @@
- (void)testMD5 - (void)testMD5
{ {
CocoaSecurity *cs = [[[CocoaSecurity alloc] init] autorelease]; CocoaSecurity *cs = [[CocoaSecurity alloc] init];
CocoaSecurityResult *md5Result = [cs md5:@"kelp"]; CocoaSecurityResult *md5Result = [cs md5:@"kelp"];
CocoaSecurityResult *hmacMd5Result = [cs hmacMd5:@"kelp" hmacKey:@"key"]; CocoaSecurityResult *hmacMd5Result = [cs hmacMd5:@"kelp" hmacKey:@"key"];
@ -93,7 +93,7 @@
- (void)testSHA - (void)testSHA
{ {
CocoaSecurity *cs = [[[CocoaSecurity alloc] init] autorelease]; CocoaSecurity *cs = [[CocoaSecurity alloc] init];
CocoaSecurityResult *sha1Result = [cs sha1:@"kelp"]; CocoaSecurityResult *sha1Result = [cs sha1:@"kelp"];
CocoaSecurityResult *sha224Result = [cs sha224:@"kelp"]; CocoaSecurityResult *sha224Result = [cs sha224:@"kelp"];
CocoaSecurityResult *sha256Result = [cs sha256:@"kelp"]; CocoaSecurityResult *sha256Result = [cs sha256:@"kelp"];

View File

@ -1,4 +1,4 @@
##CocoaSecurity 1.0 #CocoaSecurity 1.0.1
Kelp http://kelp.phate.org/ <br/> Kelp http://kelp.phate.org/ <br/>
MIT License <br/> MIT License <br/>
@ -7,7 +7,7 @@ Apache Licence 2.0: GTMBase64 by Google Inc.
CocoaSecurity include 4 classes, **CocoaSecurity**, **CocoaSecurityResult**, **CocoaSecurityEncoder** and **CocoaSecurityDecoder**. CocoaSecurity include 4 classes, **CocoaSecurity**, **CocoaSecurityResult**, **CocoaSecurityEncoder** and **CocoaSecurityDecoder**.
###CocoaSecurity ##CocoaSecurity
CocoaSecurity is core. It provides AES encrypt, AES decrypt, Hash(MD5, HmacMD5, SHA1~SHA512, HmacSHA1~HmacSHA512) messages. CocoaSecurity is core. It provides AES encrypt, AES decrypt, Hash(MD5, HmacMD5, SHA1~SHA512, HmacSHA1~HmacSHA512) messages.
<br/><br/> <br/><br/>
**MD5:** **MD5:**
@ -52,7 +52,7 @@ CocoaSecurityResult *aes256Decrypt = [cs aesDecryptWithBase64:@"WQYg5qvcGyCBY3IF
``` ```
###CocoaSecurityResult ##CocoaSecurityResult
CocoaSecurityResult is the result class of CocoaSecurity. It provides convert result data to NSData, NSString, HEX string, Base64 string. CocoaSecurityResult is the result class of CocoaSecurity. It provides convert result data to NSData, NSString, HEX string, Base64 string.
```objective-c ```objective-c
@ -64,7 +64,7 @@ CocoaSecurityResult is the result class of CocoaSecurity. It provides convert re
``` ```
###CocoaSecurityEncoder ##CocoaSecurityEncoder
CocoaSecurityEncoder provides convert NSData to HEX string, Base64 string. CocoaSecurityEncoder provides convert NSData to HEX string, Base64 string.
```objective-c ```objective-c
@ -80,7 +80,7 @@ NSString *str2 = [encoder base64:[@"kelp" dataUsingEncoding:NSUTF8StringEncoding
// str2 = 'a2VscA==' // str2 = 'a2VscA=='
``` ```
###CocoaSecurityDecoder ##CocoaSecurityDecoder
CocoaSecurityEncoder provides convert HEX string or Base64 string to NSData. CocoaSecurityEncoder provides convert HEX string or Base64 string to NSData.
```objective-c ```objective-c

View File

@ -14,8 +14,8 @@
- (void)dealloc - (void)dealloc
{ {
[_window release]; //[_window release];
[super dealloc]; //[super dealloc];
} }
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions