diff --git a/CocoaSecurity.xcodeproj/project.pbxproj b/CocoaSecurity.xcodeproj/project.pbxproj index 36f62d2..cd14f53 100644 --- a/CocoaSecurity.xcodeproj/project.pbxproj +++ b/CocoaSecurity.xcodeproj/project.pbxproj @@ -337,6 +337,7 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_ENABLE_OBJC_ARC = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; GCC_C_LANGUAGE_STANDARD = gnu99; @@ -362,6 +363,7 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_ENABLE_OBJC_ARC = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; GCC_C_LANGUAGE_STANDARD = gnu99; diff --git a/CocoaSecurity.xcodeproj/project.xcworkspace/xcuserdata/Kelp.xcuserdatad/UserInterfaceState.xcuserstate b/CocoaSecurity.xcodeproj/project.xcworkspace/xcuserdata/Kelp.xcuserdatad/UserInterfaceState.xcuserstate index 9d1809a..29f18ef 100644 Binary files a/CocoaSecurity.xcodeproj/project.xcworkspace/xcuserdata/Kelp.xcuserdatad/UserInterfaceState.xcuserstate and b/CocoaSecurity.xcodeproj/project.xcworkspace/xcuserdata/Kelp.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/CocoaSecurity/CocoaSecurity.h b/CocoaSecurity/CocoaSecurity.h index 2aec8e5..1ffe07e 100644 --- a/CocoaSecurity/CocoaSecurity.h +++ b/CocoaSecurity/CocoaSecurity.h @@ -1,9 +1,16 @@ -// -// CocoaSecurity.h -// -// Created by Kelp on 12/5/12. -// Copyright (c) 2012 Kelp http://kelp.phate.org/ -// +/* + CocoaSecurity 1.0.1 + + Created by Kelp on 12/5/12. + 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 #import diff --git a/CocoaSecurity/CocoaSecurity.m b/CocoaSecurity/CocoaSecurity.m index b0475e6..888f5d7 100644 --- a/CocoaSecurity/CocoaSecurity.m +++ b/CocoaSecurity/CocoaSecurity.m @@ -3,6 +3,7 @@ // // Created by Kelp on 12/5/12. // Copyright (c) 2012 Kelp http://kelp.phate.org/ +// MIT License // #import "CocoaSecurity.h" @@ -26,7 +27,9 @@ CocoaSecurityDecoder *decoder = [[CocoaSecurityDecoder alloc] init]; NSData *aesKey = [decoder hex:key]; NSData *aesIv = [decoder hex:iv]; +#if !__has_feature(objc_arc) [decoder release]; +#endif return [self aesEncrypt:data key:aesKey iv:aesIv]; } @@ -64,9 +67,13 @@ [data length], buffer, bufferSize, - &encryptedSize); + &encryptedSize); 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]; +#endif free(buffer); return result; @@ -94,13 +101,19 @@ CocoaSecurityDecoder *decoder = [[CocoaSecurityDecoder alloc] init]; NSData *aesKey = [decoder hex:key]; NSData *aesIv = [decoder hex:iv]; +#if !__has_feature(objc_arc) [decoder release]; +#endif return [self aesDecryptWithBase64:data key:aesKey iv:aesIv]; } - (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]; +#endif return [self aesDecryptWithData:[decoder base64:data] key:key iv:iv]; } @@ -134,9 +147,13 @@ [data length], buffer, bufferSize, - &encryptedSize); + &encryptedSize); 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]; +#endif free(buffer); return result; @@ -160,7 +177,11 @@ digest = malloc(CC_MD5_DIGEST_LENGTH); 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]; +#endif free(digest); return result; @@ -177,7 +198,11 @@ const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding]; 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]; +#endif free(digest); cKey = nil; @@ -195,7 +220,11 @@ digest = malloc(CC_SHA1_DIGEST_LENGTH); 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]; +#endif free(digest); return result; @@ -211,7 +240,11 @@ digest = malloc(CC_SHA224_DIGEST_LENGTH); 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]; +#endif free(digest); return result; @@ -227,7 +260,11 @@ digest = malloc(CC_SHA256_DIGEST_LENGTH); 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]; +#endif free(digest); return result; @@ -243,7 +280,11 @@ digest = malloc(CC_SHA384_DIGEST_LENGTH); 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]; +#endif free(digest); return result; @@ -259,7 +300,11 @@ digest = malloc(CC_SHA512_DIGEST_LENGTH); 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]; +#endif free(digest); return result; @@ -277,7 +322,11 @@ const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding]; 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]; +#endif free(digest); cKey = nil; @@ -295,7 +344,11 @@ const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding]; 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]; +#endif free(digest); cKey = nil; @@ -313,7 +366,11 @@ const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding]; 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]; +#endif free(digest); cKey = nil; @@ -331,7 +388,11 @@ const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding]; 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]; +#endif free(digest); cKey = nil; @@ -349,7 +410,11 @@ const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding]; 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]; +#endif free(digest); cKey = nil; @@ -376,7 +441,11 @@ // convert CocoaSecurityResult to UTF8 string - (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]; +#endif return result; } @@ -385,13 +454,21 @@ // convert CocoaSecurityResult to HEX string - (NSString *)hex { +#if __has_feature(objc_arc) + CocoaSecurityEncoder *encoder = [[CocoaSecurityEncoder alloc] init]; +#else CocoaSecurityEncoder *encoder = [[[CocoaSecurityEncoder alloc] init] autorelease]; +#endif return [encoder hex:data useLower:false]; } - (NSString *)hexLower { +#if __has_feature(objc_arc) + CocoaSecurityEncoder *encoder = [[CocoaSecurityEncoder alloc] init]; +#else CocoaSecurityEncoder *encoder = [[[CocoaSecurityEncoder alloc] init] autorelease]; +#endif return [encoder hex:data useLower:true]; } @@ -400,7 +477,11 @@ // convert CocoaSecurityResult to Base64 string - (NSString *)base64 { +#if __has_feature(objc_arc) + CocoaSecurityEncoder *encoder = [[CocoaSecurityEncoder alloc] init]; +#else CocoaSecurityEncoder *encoder = [[[CocoaSecurityEncoder alloc] init] autorelease]; +#endif return [encoder base64:data]; } @@ -416,7 +497,11 @@ { // base on GTMBase64 NSString *result = [[NSString alloc] initWithData:[GTMBase64 encodeData:data] encoding:NSUTF8StringEncoding]; +#if __has_feature(objc_arc) + return result; +#else return [result autorelease]; +#endif } // convert NSData to hex string @@ -464,7 +549,11 @@ { // base on GTMBase64 NSData *result = [[NSData alloc] initWithData:[GTMBase64 decodeString:data]]; +#if __has_feature(objc_arc) + return result; +#else return [result autorelease]; +#endif } - (NSData *)hex: (NSString *)data diff --git a/CocoaSecurity/GTMBase64/CocoaSecurity-GTMBase64.m b/CocoaSecurity/GTMBase64/CocoaSecurity-GTMBase64.m index cb1a0c9..aeaf5d2 100644 --- a/CocoaSecurity/GTMBase64/CocoaSecurity-GTMBase64.m +++ b/CocoaSecurity/GTMBase64/CocoaSecurity-GTMBase64.m @@ -283,8 +283,13 @@ GTM_INLINE NSUInteger GuessDecodedLength(NSUInteger srcLen) { charset:kBase64EncodeChars padded:YES]; 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]; +#endif } return result; } @@ -296,8 +301,13 @@ GTM_INLINE NSUInteger GuessDecodedLength(NSUInteger srcLen) { charset:kBase64EncodeChars padded:YES]; 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]; +#endif } return result; } @@ -362,8 +372,13 @@ GTM_INLINE NSUInteger GuessDecodedLength(NSUInteger srcLen) { charset:kWebSafeBase64EncodeChars padded:padded]; 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]; +#endif } return result; } @@ -377,8 +392,13 @@ GTM_INLINE NSUInteger GuessDecodedLength(NSUInteger srcLen) { charset:kWebSafeBase64EncodeChars padded:padded]; 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]; +#endif } return result; } diff --git a/CocoaSecurityTests/CocoaSecurityTests.m b/CocoaSecurityTests/CocoaSecurityTests.m index a905ff1..1150da0 100644 --- a/CocoaSecurityTests/CocoaSecurityTests.m +++ b/CocoaSecurityTests/CocoaSecurityTests.m @@ -26,8 +26,8 @@ - (void)testEncodeDecode { - CocoaSecurityDecoder *decoder = [[[CocoaSecurityDecoder alloc] init] autorelease]; - CocoaSecurityEncoder *encoder = [[[CocoaSecurityEncoder alloc] init] autorelease]; + CocoaSecurityDecoder *decoder = [[CocoaSecurityDecoder alloc] init]; + CocoaSecurityEncoder *encoder = [[CocoaSecurityEncoder alloc] init]; // HEX STAssertEqualObjects([encoder hex:[decoder hex:@"CC0A69779E15780ADAE46C45EB451A23"] useLower:false], @@ -39,8 +39,8 @@ - (void)testAES { - CocoaSecurity *cs = [[[CocoaSecurity alloc] init] autorelease]; - CocoaSecurityDecoder *decoder = [[[CocoaSecurityDecoder alloc] init] autorelease]; + CocoaSecurity *cs = [[CocoaSecurity alloc] init]; + CocoaSecurityDecoder *decoder = [[CocoaSecurityDecoder alloc] init]; // AES128 CocoaSecurityResult *aes128 = [cs aesEncryptWithData:[@"kelp" dataUsingEncoding:NSUTF8StringEncoding] @@ -78,7 +78,7 @@ - (void)testMD5 { - CocoaSecurity *cs = [[[CocoaSecurity alloc] init] autorelease]; + CocoaSecurity *cs = [[CocoaSecurity alloc] init]; CocoaSecurityResult *md5Result = [cs md5:@"kelp"]; CocoaSecurityResult *hmacMd5Result = [cs hmacMd5:@"kelp" hmacKey:@"key"]; @@ -93,7 +93,7 @@ - (void)testSHA { - CocoaSecurity *cs = [[[CocoaSecurity alloc] init] autorelease]; + CocoaSecurity *cs = [[CocoaSecurity alloc] init]; CocoaSecurityResult *sha1Result = [cs sha1:@"kelp"]; CocoaSecurityResult *sha224Result = [cs sha224:@"kelp"]; CocoaSecurityResult *sha256Result = [cs sha256:@"kelp"]; diff --git a/README.md b/README.md index d8b38e9..129f614 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -##CocoaSecurity 1.0 +#CocoaSecurity 1.0.1 Kelp http://kelp.phate.org/
MIT License
@@ -7,7 +7,7 @@ Apache Licence 2.0: GTMBase64 by Google Inc. 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.

**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. ```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. ```objective-c @@ -80,7 +80,7 @@ NSString *str2 = [encoder base64:[@"kelp" dataUsingEncoding:NSUTF8StringEncoding // str2 = 'a2VscA==' ``` -###CocoaSecurityDecoder +##CocoaSecurityDecoder CocoaSecurityEncoder provides convert HEX string or Base64 string to NSData. ```objective-c diff --git a/iOS View/CocoaSecurityAppDelegate.m b/iOS View/CocoaSecurityAppDelegate.m index 46b1ed2..e6df9d6 100644 --- a/iOS View/CocoaSecurityAppDelegate.m +++ b/iOS View/CocoaSecurityAppDelegate.m @@ -14,8 +14,8 @@ - (void)dealloc { - [_window release]; - [super dealloc]; + //[_window release]; + //[super dealloc]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions