Skip to content

Instantly share code, notes, and snippets.

@florentmorin
Last active December 19, 2017 10:10
Show Gist options
  • Save florentmorin/5a76291075cebee68e57820c6d353a13 to your computer and use it in GitHub Desktop.
Save florentmorin/5a76291075cebee68e57820c6d353a13 to your computer and use it in GitHub Desktop.
Non-modular integration of Common Crypto library into Swift Framework
@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>
import Foundation
open class MySDK {
open class func md5sum(input: String) -> String? {
return MySDKCrypto.md5Hash(input)
}
}
#import <Foundation/Foundation.h>
@interface MySDKCrypto : NSObject
+ (NSString *)md5Hash:(NSString *)string;
@end
#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