Skip to content

Instantly share code, notes, and snippets.

@mczachurski
Created March 2, 2018 10:59
Show Gist options
  • Save mczachurski/37c0294e25d9081df84edd58da710c05 to your computer and use it in GitHub Desktop.
Save mczachurski/37c0294e25d9081df84edd58da710c05 to your computer and use it in GitHub Desktop.
public func generateHash(salt: String) throws -> String {
let stringWithSalt = salt + self
guard let stringArray = stringWithSalt.digest(.sha256)?.encode(.base64) else {
throw GeneratePasswordError()
}
guard let stringHash = String(data: Data(bytes: stringArray, count: stringArray.count), encoding: .utf8) else {
throw GeneratePasswordError()
}
return stringHash
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment