open static func PBKDF2(_ password: String, salt: Data,
prf: PRFAlg, rounds: UInt32) throws -> Data {
var result = Data(count:prf.cc.digestLength)
let passwData = password.data(using: String.Encoding.utf8)!
let status = result.withUnsafeMutableBytes {
(passwDataBytes: UnsafeMutablePointer<UInt8>) -> CCCryptorStatus in
return CCKeyDerivationPBKDF!(PBKDFAlgorithm.pbkdf2.rawValue,
(passwData as NSData).bytes, passwData.count,
(salt as NSData).bytes, salt.count,
prf.rawValue, rounds,
passwDataBytes, result.count)
}
guard status == noErr else { throw CCError(status) }
return result
}
Run Code Online (Sandbox Code Playgroud)
result.withUnsafeMutableBytes在Xcode 10中给出错误,在Xcode 9中它是一个警告.