Last active
December 19, 2017 10:10
-
-
Save florentmorin/5a76291075cebee68e57820c6d353a13 to your computer and use it in GitHub Desktop.
Non-modular integration of Common Crypto library into Swift Framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import Foundation; | |
//! Project version number for MySDK. | |
FOUNDATION_EXPORT double MySDKVersionNumber; | |
//! Project version string for MySDK. | |
FOUNDATION_EXPORT const unsigned char MySDKVersionString[]; | |
// In this header, you should import all the public headers of your framework using statements like #import <MySDK/PublicHeader.h> | |
#import <MySDK/MySDKCrypto.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
open class MySDK { | |
open class func md5sum(input: String) -> String? { | |
return MySDKCrypto.md5Hash(input) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface MySDKCrypto : NSObject | |
+ (NSString *)md5Hash:(NSString *)string; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "MySDKCrypto.h" | |
#import <CommonCrypto/CommonCrypto.h> | |
@implementation MySDKCrypto | |
+ (NSString *)md5Hash:(NSString *)string { | |
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding]; | |
unsigned char result[CC_MD5_DIGEST_LENGTH]; | |
CC_MD5(data.bytes, (int)data.length, result); | |
return [NSString stringWithFormat: | |
@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", | |
result[0], result[1], result[2], result[3], | |
result[4], result[5], result[6], result[7], | |
result[8], result[9], result[10], result[11], | |
result[12], result[13], result[14], result[15] | |
]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment