Commit 0785eaf1 authored by Dapperstout's avatar Dapperstout

Added IGDigest library.

parent 91880f68
......@@ -5,4 +5,5 @@ link_with 'pulse', 'pulseTests'
pod 'CocoaAsyncSocket', '~> 7.3', :inhibit_warnings => true
pod 'lz4', '~> 123'
pod 'Base32', '~> 1.0.2'
\ No newline at end of file
pod 'Base32', '~> 1.0.2'
pod 'IGDigest', '~> 1.1.0'
\ No newline at end of file
PODS:
- Base32 (1.0.2)
- CocoaAsyncSocket (7.3.5)
- IGDigest (1.1.0)
- lz4 (123)
DEPENDENCIES:
- Base32 (~> 1.0.2)
- CocoaAsyncSocket (~> 7.3)
- IGDigest (~> 1.1.0)
- lz4 (~> 123)
SPEC CHECKSUMS:
Base32: a0ef6e90e721130c474cc970a4d98a6cbf16ce85
CocoaAsyncSocket: 45bdbbc1c0a5ed0640ff4c42af325ba43a2f099a
IGDigest: 9d142a7926ecc2983e6208d938ac5dddd26ed9c2
lz4: 316468bb1b748b046e7d4452e46ffc5c7fddccf0
COCOAPODS: 0.34.4
COCOAPODS: 0.35.0
../../../IGDigest/IGDigest/HMAC/IGHMAC.h
\ No newline at end of file
../../../IGDigest/IGDigest/Digest/NSData+MD5Digest.h
\ No newline at end of file
../../../IGDigest/IGDigest/Digest/NSData+SHA1Digest.h
\ No newline at end of file
../../../IGDigest/IGDigest/Digest/NSData+SHA256Digest.h
\ No newline at end of file
../../../IGDigest/IGDigest/Digest/NSString+MD5Digest.h
\ No newline at end of file
../../../IGDigest/IGDigest/HMAC/NSString+MD5HMAC.h
\ No newline at end of file
../../../IGDigest/IGDigest/Digest/NSString+SHA1Digest.h
\ No newline at end of file
../../../IGDigest/IGDigest/HMAC/NSString+SHA1HMAC.h
\ No newline at end of file
../../../IGDigest/IGDigest/Digest/NSString+SHA256Digest.h
\ No newline at end of file
../../../IGDigest/IGDigest/HMAC/NSString+SHA256HMAC.h
\ No newline at end of file
../../../IGDigest/IGDigest/HMAC/IGHMAC.h
\ No newline at end of file
../../../IGDigest/IGDigest/Digest/NSData+MD5Digest.h
\ No newline at end of file
../../../IGDigest/IGDigest/Digest/NSData+SHA1Digest.h
\ No newline at end of file
../../../IGDigest/IGDigest/Digest/NSData+SHA256Digest.h
\ No newline at end of file
../../../IGDigest/IGDigest/Digest/NSString+MD5Digest.h
\ No newline at end of file
../../../IGDigest/IGDigest/HMAC/NSString+MD5HMAC.h
\ No newline at end of file
../../../IGDigest/IGDigest/Digest/NSString+SHA1Digest.h
\ No newline at end of file
../../../IGDigest/IGDigest/HMAC/NSString+SHA1HMAC.h
\ No newline at end of file
../../../IGDigest/IGDigest/Digest/NSString+SHA256Digest.h
\ No newline at end of file
../../../IGDigest/IGDigest/HMAC/NSString+SHA256HMAC.h
\ No newline at end of file
//
// NSData+MD5Digest.h
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSData (MD5Digest)
+(NSData *)MD5Digest:(NSData *)input;
-(NSData *)MD5Digest;
+(NSString *)MD5HexDigest:(NSData *)input;
-(NSString *)MD5HexDigest;
@end
\ No newline at end of file
//
// NSData+MD5Digest.m
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import "NSData+MD5Digest.h"
#import <CommonCrypto/CommonDigest.h>
@implementation NSData (MD5)
+(NSData *)MD5Digest:(NSData *)input {
unsigned char result[CC_MD5_DIGEST_LENGTH];
if (CC_MD5(input.bytes, input.length, result)) {
return [[NSData alloc] initWithBytes:result length:CC_MD5_DIGEST_LENGTH];
} else {
return nil;
}
}
-(NSData *)MD5Digest {
return [NSData MD5Digest:self];
}
+(NSString *)MD5HexDigest:(NSData *)input {
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5(input.bytes, input.length, result);
NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH*2];
for (int i = 0; i<CC_MD5_DIGEST_LENGTH; i++) {
[ret appendFormat:@"%02x",result[i]];
}
return ret;
}
-(NSString *)MD5HexDigest {
return [NSData MD5HexDigest:self];
}
@end
\ No newline at end of file
//
// NSData+SHA1Digest.h
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSData (SHA1Digest)
+(NSData *)SHA1Digest:(NSData *)input;
-(NSData *)SHA1Digest;
+(NSString *)SHA1HexDigest:(NSData *)input;
-(NSString *)SHA1HexDigest;
@end
//
// NSData+SHA1Digest.m
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import "NSData+SHA1Digest.h"
#import <CommonCrypto/CommonDigest.h>
@implementation NSData (SHA1Digest)
+(NSData *)SHA1Digest:(NSData *)input {
unsigned char result[CC_SHA1_DIGEST_LENGTH];
if (CC_SHA1(input.bytes, input.length, result)) {
return [[NSData alloc] initWithBytes:result length:CC_SHA1_DIGEST_LENGTH];
} else {
return nil;
}
}
-(NSData *)SHA1Digest {
return [NSData SHA1Digest:self];
}
+(NSString *)SHA1HexDigest:(NSData *)input {
unsigned char result[CC_SHA1_DIGEST_LENGTH];
if (CC_SHA1(input.bytes, input.length, result)) {
NSMutableString *ret = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH*2];
for (int i = 0; i<CC_SHA1_DIGEST_LENGTH; i++) {
[ret appendFormat:@"%02x",result[i]];
}
return ret;
} else {
return nil;
}
}
-(NSString *)SHA1HexDigest {
return [NSData SHA1HexDigest:self];
}
@end
//
// NSData+SHA256Digest.h
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSData (SHA256Digest)
+(NSData *)SHA256Digest:(NSData *)input;
-(NSData *)SHA256Digest;
+(NSString *)SHA256HexDigest:(NSData *)input;
-(NSString *)SHA256HexDigest;
@end
//
// NSData+SHA256Digest.m
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import "NSData+SHA256Digest.h"
#import <CommonCrypto/CommonDigest.h>
@implementation NSData (SHA256Digest)
+(NSData *)SHA256Digest:(NSData *)input {
unsigned char result[CC_SHA256_DIGEST_LENGTH];
if (CC_SHA256(input.bytes, input.length, result)) {
return [[NSData alloc] initWithBytes:result length:CC_SHA256_DIGEST_LENGTH];
} else {
return nil;
}
}
-(NSData *)SHA256Digest {
return [NSData SHA256Digest:self];
}
+(NSString *)SHA256HexDigest:(NSData *)input {
unsigned char result[CC_SHA256_DIGEST_LENGTH];
if (CC_SHA256(input.bytes, input.length, result)) {
NSMutableString *ret = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH*2];
for (int i = 0; i<CC_SHA256_DIGEST_LENGTH; i++) {
[ret appendFormat:@"%02x",result[i]];
}
return ret;
} else {
return nil;
}
}
-(NSString *)SHA256HexDigest {
return [NSData SHA256HexDigest:self];
}
@end
//
// NSString+MD5Digest.h
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSString (MD5Digest)
+(NSData *)MD5Digest:(NSString *)input encoding:(NSStringEncoding)encoding;
-(NSData *)MD5DigestWithEncoding:(NSStringEncoding)encoding;
-(NSData *)MD5Digest;
+(NSString *)MD5HexDigest:(NSString *)input encoding:(NSStringEncoding)encoding;
-(NSString *)MD5HexDigestWithEncoding:(NSStringEncoding)encoding;
-(NSString *)MD5HexDigest;
@end
//
// NSString+MD5Digest.m
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import "NSString+MD5Digest.h"
#import "NSData+MD5Digest.h"
@implementation NSString (MD5Digest)
+(NSData *)MD5Digest:(NSString *)input encoding:(NSStringEncoding)encoding {
NSData* data = [input dataUsingEncoding:encoding];
return [data MD5Digest];
}
-(NSData *)MD5DigestWithEncoding:(NSStringEncoding)encoding {
NSData* data = [self dataUsingEncoding:encoding];
return [data MD5Digest];
}
-(NSData *)MD5Digest {
return [self MD5DigestWithEncoding:NSUTF8StringEncoding];
}
+(NSString *)MD5HexDigest:(NSString *)input encoding:(NSStringEncoding)encoding {
NSData* data = [input dataUsingEncoding:encoding];
return [data MD5HexDigest];
}
-(NSString *)MD5HexDigestWithEncoding:(NSStringEncoding)encoding {
NSData* data = [self dataUsingEncoding:encoding];
return [data MD5HexDigest];
}
-(NSString *)MD5HexDigest {
return [self MD5HexDigestWithEncoding:NSUTF8StringEncoding];
}
@end
//
// NSString+SHA1Digest.h
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSString (SHA1Digest)
+(NSData *)SHA1Digest:(NSString *)input encoding:(NSStringEncoding)encoding;
-(NSData *)SHA1DigestWithEncoding:(NSStringEncoding)encoding;
-(NSData *)SHA1Digest;
+(NSString *)SHA1HexDigest:(NSString *)input encoding:(NSStringEncoding)encoding;
-(NSString *)SHA1HexDigestWithEncoding:(NSStringEncoding)encoding;
-(NSString *)SHA1HexDigest;
@end
//
// NSString+SHA1Digest.m
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import "NSString+SHA1Digest.h"
#import "NSData+SHA1Digest.h"
@implementation NSString (SHA1Digest)
+(NSData *)SHA1Digest:(NSString *)input encoding:(NSStringEncoding)encoding {
NSData* data = [input dataUsingEncoding:encoding];
return [data SHA1Digest];
}
-(NSData *)SHA1DigestWithEncoding:(NSStringEncoding)encoding {
NSData* data = [self dataUsingEncoding:encoding];
return [data SHA1Digest];
}
-(NSData *)SHA1Digest {
return [self SHA1DigestWithEncoding:NSUTF8StringEncoding];
}
+(NSString *)SHA1HexDigest:(NSString *)input encoding:(NSStringEncoding)encoding {
NSData* data = [input dataUsingEncoding:encoding];
return [data SHA1HexDigest];
}
-(NSString *)SHA1HexDigestWithEncoding:(NSStringEncoding)encoding {
NSData* data = [self dataUsingEncoding:encoding];
return [data SHA1HexDigest];
}
-(NSString *)SHA1HexDigest {
return [self SHA1HexDigestWithEncoding:NSUTF8StringEncoding];
}
@end
//
// NSString+SHA256Digest.h
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSString (SHA256Digest)
+(NSData *)SHA256Digest:(NSString *)input encoding:(NSStringEncoding)encoding;
-(NSData *)SHA256DigestWithEncoding:(NSStringEncoding)encoding;
-(NSData *)SHA256Digest;
+(NSString *)SHA256HexDigest:(NSString *)input encoding:(NSStringEncoding)encoding;
-(NSString *)SHA256HexDigestWithEncoding:(NSStringEncoding)encoding;
-(NSString *)SHA256HexDigest;
@end
//
// NSString+SHA256Digest.m
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import "NSString+SHA256Digest.h"
#import "NSData+SHA256Digest.h"
@implementation NSString (SHA256Digest)
+(NSData *)SHA256Digest:(NSString *)input encoding:(NSStringEncoding)encoding {
NSData* data = [input dataUsingEncoding:encoding];
return [data SHA256Digest];
}
-(NSData *)SHA256DigestWithEncoding:(NSStringEncoding)encoding {
NSData* data = [self dataUsingEncoding:encoding];
return [data SHA256Digest];
}
-(NSData *)SHA256Digest {
return [self SHA256DigestWithEncoding:NSUTF8StringEncoding];
}
+(NSString *)SHA256HexDigest:(NSString *)input encoding:(NSStringEncoding)encoding {
NSData* data = [input dataUsingEncoding:encoding];
return [data SHA256HexDigest];
}
-(NSString *)SHA256HexDigestWithEncoding:(NSStringEncoding)encoding {
NSData* data = [self dataUsingEncoding:encoding];
return [data SHA256HexDigest];
}
-(NSString *)SHA256HexDigest {
return [self SHA256HexDigestWithEncoding:NSUTF8StringEncoding];
}
@end
//
// IGHMAC.h
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import <Foundation/Foundation.h>
#include <CommonCrypto/CommonDigest.h>
#include <CommonCrypto/CommonHMAC.h>
@interface IGHMAC : NSObject
+(NSString *)HMACWithMessage:(NSString*)message key:(NSString*)key encoding:(NSStringEncoding)encoding algorithm:(CCHmacAlgorithm)algorithm digestLength:(NSInteger)digestLength;
@end
//
// IGHMAC.m
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import "IGHMAC.h"
#include <CommonCrypto/CommonDigest.h>
#include <CommonCrypto/CommonHMAC.h>
@implementation IGHMAC
+(NSString *)HMACWithMessage:(NSString*)message key:(NSString*)key encoding:(NSStringEncoding)encoding algorithm:(CCHmacAlgorithm)algorithm digestLength:(NSInteger)digestLength{
const char *cKey = [key cStringUsingEncoding:encoding];
const char *cMessage = [message cStringUsingEncoding:encoding];
unsigned char result[digestLength];
CCHmac(algorithm, cKey, strlen(cKey), cMessage, strlen(cMessage), result);
NSMutableString *ret = [NSMutableString stringWithCapacity:digestLength*2];
for (int i = 0; i<digestLength; i++) {
[ret appendFormat:@"%02x", result[i]];
}
return ret;
}
@end
//
// NSString+MD5HMAC.h
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSString (MD5HMAC)
-(NSString *)MD5HMACWithKey:(NSString*)key encoding:(NSStringEncoding)encoding;
-(NSString *)MD5HMACWithKey:(NSString*)key;
@end
//
// NSString+MD5HMAC.m
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import "NSString+MD5HMAC.h"
#import "IGHMAC.h"
@implementation NSString (MD5HMAC)
-(NSString *)MD5HMACWithKey:(NSString*)key encoding:(NSStringEncoding)encoding {
return [IGHMAC HMACWithMessage:self
key:key
encoding:encoding
algorithm:kCCHmacAlgMD5
digestLength:CC_MD5_DIGEST_LENGTH];
}
-(NSString *)MD5HMACWithKey:(NSString*)key {
return [self MD5HMACWithKey:key
encoding:NSUTF8StringEncoding];
}
@end
//
// NSString+SHA1HMAC.h
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSString (SHA1HMAC)
-(NSString *)SHA1HMACWithKey:(NSString*)key encoding:(NSStringEncoding)encoding;
-(NSString *)SHA1HMACWithKey:(NSString*)key;
@end
//
// NSString+SHA1HMAC.m
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import "NSString+SHA1HMAC.h"
#import "IGHMAC.h"
@implementation NSString (SHA1HMAC)
-(NSString *)SHA1HMACWithKey:(NSString*)key encoding:(NSStringEncoding)encoding {
return [IGHMAC HMACWithMessage:self
key:key
encoding:encoding
algorithm:kCCHmacAlgSHA1
digestLength:CC_SHA1_DIGEST_LENGTH];
}
-(NSString *)SHA1HMACWithKey:(NSString*)key {
return [self SHA1HMACWithKey:key
encoding:NSUTF8StringEncoding];
}
@end
//
// NSString+HMAC_SHA256.h
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSString (SHA256HMAC)
-(NSString *)SHA256HMACWithKey:(NSString*)key encoding:(NSStringEncoding)encoding;
-(NSString *)SHA256HMACWithKey:(NSString*)key;
@end
//
// NSString+HMAC_SHA256.m
// IGDigest
//
// Created by Chong Francis on 13年4月1日.
// Copyright (c) 2013年 Ignition Soft. All rights reserved.
//
#import "NSString+SHA256HMAC.h"
#import "IGHMAC.h"
@implementation NSString (SHA256HMAC)
-(NSString *)SHA256HMACWithKey:(NSString*)key encoding:(NSStringEncoding)encoding {
return [IGHMAC HMACWithMessage:self
key:key
encoding:encoding
algorithm:kCCHmacAlgSHA256
digestLength:CC_SHA256_DIGEST_LENGTH];
}
-(NSString *)SHA256HMACWithKey:(NSString*)key {
return [self SHA256HMACWithKey:key
encoding:NSUTF8StringEncoding];
}
@end
Copyright (c) 2013 Francis Chong
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
## IGDigest
Provides convenient wrappers for popular message digest formats (MD5, SHA1 and SHA256) and HMAC (Hash-based message authentication code).
### Examples
#### Using message digest