Created
December 3, 2019 11:15
-
-
Save albertodebortoli/675a5dcf5a36d1853c972e07b4f367d2 to your computer and use it in GitHub Desktop.
used by 'Lessons learned from handling JWT on mobile' article on Medium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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