Created
April 30, 2018 09:00
-
-
Save kimjj81/4f0f21a7ffeb1532e55e356d20ee1bf0 to your computer and use it in GitHub Desktop.
PBKDF2 Objective-c
This file contains hidden or 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 <CommonCrypto/CommonCrypto.h> | |
+ (NSString*)onewayHash:(NSString *)text { | |
NSMutableData *key = [NSMutableData dataWithLength:kCCKeySizeAES256]; | |
NSString *password = text; | |
NSString* saltText = @"salt"; | |
NSData* salt = [saltText dataUsingEncoding:NSUTF8StringEncoding]; | |
int result = CCKeyDerivationPBKDF(kCCPBKDF2, // algorithm | |
password.UTF8String, // password | |
password.length, // passwordLength | |
salt.bytes, // salt | |
salt.length, // saltLen | |
kCCPRFHmacAlgSHA1, // PRF | |
10, // rounds | |
key.mutableBytes, // derivedKey | |
key.length); // derivedKeyLen | |
NSString *sKey= [key base64EncodedStringWithOptions:0]; | |
return sKey; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment