Skip to content

Instantly share code, notes, and snippets.

@kimjj81
Created April 30, 2018 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimjj81/4f0f21a7ffeb1532e55e356d20ee1bf0 to your computer and use it in GitHub Desktop.
Save kimjj81/4f0f21a7ffeb1532e55e356d20ee1bf0 to your computer and use it in GitHub Desktop.
PBKDF2 Objective-c
#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