add method: sharedInstance
This commit is contained in:
parent
e78c9a9f1e
commit
cf44f338e1
Binary file not shown.
@ -42,6 +42,9 @@
|
|||||||
|
|
||||||
#pragma mark - CocoaSecurity
|
#pragma mark - CocoaSecurity
|
||||||
@interface CocoaSecurity : NSObject
|
@interface CocoaSecurity : NSObject
|
||||||
|
#pragma mark - Init
|
||||||
|
+ (id)sharedInstance;
|
||||||
|
|
||||||
#pragma mark - AES Encrypt
|
#pragma mark - AES Encrypt
|
||||||
- (CocoaSecurityResult *)aesEncrypt:(NSString *)data key:(NSString *)key;
|
- (CocoaSecurityResult *)aesEncrypt:(NSString *)data key:(NSString *)key;
|
||||||
- (CocoaSecurityResult *)aesEncrypt:(NSString *)data hexKey:(NSString *)key hexIv:(NSString *)iv;
|
- (CocoaSecurityResult *)aesEncrypt:(NSString *)data hexKey:(NSString *)key hexIv:(NSString *)iv;
|
||||||
|
|||||||
@ -11,6 +11,17 @@
|
|||||||
#pragma mark - CocoaSecurity
|
#pragma mark - CocoaSecurity
|
||||||
@implementation CocoaSecurity
|
@implementation CocoaSecurity
|
||||||
|
|
||||||
|
static CocoaSecurity *_instance = nil;
|
||||||
|
|
||||||
|
#pragma mark - Init
|
||||||
|
+ (id)sharedInstance
|
||||||
|
{
|
||||||
|
if (_instance == nil) {
|
||||||
|
_instance = [self new];
|
||||||
|
}
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - AES Encrypt
|
#pragma mark - AES Encrypt
|
||||||
// default AES Encrypt, key -> SHA384(key).sub(0, 32), iv -> SHA384(key).sub(32, 16)
|
// default AES Encrypt, key -> SHA384(key).sub(0, 32), iv -> SHA384(key).sub(32, 16)
|
||||||
- (CocoaSecurityResult *)aesEncrypt:(NSString *)data key:(NSString *)key
|
- (CocoaSecurityResult *)aesEncrypt:(NSString *)data key:(NSString *)key
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
// CocoaSecurityTests
|
// CocoaSecurityTests
|
||||||
//
|
//
|
||||||
// Created by Kelp on 12/5/13.
|
// Created by Kelp on 12/5/13.
|
||||||
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
|
// Copyright (c) 2012 Phate. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <SenTestingKit/SenTestingKit.h>
|
#import <SenTestingKit/SenTestingKit.h>
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
// CocoaSecurityTests
|
// CocoaSecurityTests
|
||||||
//
|
//
|
||||||
// Created by Kelp on 12/5/13.
|
// Created by Kelp on 12/5/13.
|
||||||
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
|
// Copyright (c) 2012 Phate. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "CocoaSecurityTests.h"
|
#import "CocoaSecurityTests.h"
|
||||||
@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
- (void)testAES
|
- (void)testAES
|
||||||
{
|
{
|
||||||
CocoaSecurity *cs = [[CocoaSecurity alloc] init];
|
CocoaSecurity *cs = [CocoaSecurity sharedInstance];
|
||||||
CocoaSecurityDecoder *decoder = [[CocoaSecurityDecoder alloc] init];
|
CocoaSecurityDecoder *decoder = [[CocoaSecurityDecoder alloc] init];
|
||||||
|
|
||||||
// AES128
|
// AES128
|
||||||
@ -78,7 +78,7 @@
|
|||||||
|
|
||||||
- (void)testMD5
|
- (void)testMD5
|
||||||
{
|
{
|
||||||
CocoaSecurity *cs = [[CocoaSecurity alloc] init];
|
CocoaSecurity *cs = [CocoaSecurity sharedInstance];
|
||||||
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];
|
CocoaSecurity *cs = [CocoaSecurity sharedInstance];
|
||||||
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"];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user