2
PBKDF2在CryptoJS和iOS中結果不同。PBKDF2結果在CryptoJS和iOS中有所不同
這裏是我的代碼
CryptoJS
var key= CryptoJS.PBKDF2("gf8uny", "2mnfpLsa+5I=", { keySize: 256/32, iterations: 1000 });
console.log(key.toString(CryptoJS.enc.Base64));
// console output ANepH98DqZHtMkkVrIk/CNmfykVPfEFpoax2PF8z5k8=
的iOS
NSMutableData *key = [NSMutableData dataWithLength:kCCKeySizeAES256];
NSString *password = @"gf8uny";
NSData*salt =[NSData dataFromBase64String:@"2mnfpLsa+5I="];
int result = CCKeyDerivationPBKDF(kCCPBKDF2, // algorithm
password.UTF8String, // password
password.length, // passwordLength
salt.bytes, // salt
salt.length, // saltLen
kCCPRFHmacAlgSHA1, // PRF
1000, // rounds
key.mutableBytes, // derivedKey
key.length); // derivedKeyLen
NSString *sKey= [key base64EncodedString];
NSLog(@"key%@", sKey);
// output AjHjVAwHCpF1SnNDN6ri9ms7ig88VFBPwRVRMppBgnU=
有人能幫忙嗎?我做錯了什麼?
感謝