Skip to content

Instantly share code, notes, and snippets.

@araeuchle
Created August 23, 2019 14:38
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 araeuchle/ce7b72d618a9d35e56e0220e56a3b25a to your computer and use it in GitHub Desktop.
Save araeuchle/ce7b72d618a9d35e56e0220e56a3b25a to your computer and use it in GitHub Desktop.
func encode(apiKey: String) throws -> String {
guard let apiKeyData = "api:\(apiKey)".data(using: .utf8) else {
throw Error.encodingProblem
}
let authKey = apiKeyData.base64EncodedData()
guard let authKeyEncoded = String.init(data: authKey, encoding: .utf8) else {
throw Error.encodingProblem
}
return authKeyEncoded
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment