If you want to reproduce the same encryption as Symfony2 with the 5000 iterations, you can use the following code:
- (NSString *)hashPassword:(NSString *)password ansSalt:(NSString *)salt {
NSString *passwordSalted = [NSString stringWithFormat:@"%@{%@}",password,salt];
NSData *passwordData = [passwordSalted dataUsingEncoding:NSUTF8StringEncoding];
uint8_t hash[CC_SHA512_DIGEST_LENGTH];
CC_SHA512([passwordData bytes], [passwordData length], hash);
NSMutableData *allData = [[NSMutableData alloc] init];
[allData appendBytes:hash length:CC_SHA512_DIGEST_LENGTH];
for (NSInteger i = 1; i < 5000; i++) {
[allData appendBytes:[passwordData bytes] length:[passwordData length]];
uint8_t hashLoop[CC_SHA512_DIGEST_LENGTH];
CC_SHA512([allData bytes], [allData length], hashLoop);
[allData setLength:0];
[allData appendBytes:hashLoop length:CC_SHA512_DIGEST_LENGTH];
}
NSData *imageData = [NSData dataWithBytes:[allData bytes] length:[allData length]];
return [imageData base64EncodedStringWithOptions:0];
}
Don't forgot to import CommonDigest.h:
#import <CommonCrypto/CommonDigest.h>