Skip to content

Instantly share code, notes, and snippets.

@albertodebortoli
Created December 3, 2019 11:15
Show Gist options
  • Save albertodebortoli/675a5dcf5a36d1853c972e07b4f367d2 to your computer and use it in GitHub Desktop.
Save albertodebortoli/675a5dcf5a36d1853c972e07b4f367d2 to your computer and use it in GitHub Desktop.
used by 'Lessons learned from handling JWT on mobile' article on Medium
func base64String(_ input: String) -> String {
var base64 = input
.replacingOccurrences(of: "-", with: "+")
.replacingOccurrences(of: "_", with: "/")
switch base64.count % 4 {
case 2:
base64 = base64.appending("==")
case 3:
base64 = base64.appending("=")
default:
break
}
return base64
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment