Skip to content

Commit b689dc0

Browse files
committed
Improve base 64 URI decoder
1 parent 5a862f1 commit b689dc0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

JWT/JWT.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ func base64decode(input:String) -> NSData? {
4646
ending = String(count: amount, repeatedValue: Character("="))
4747
}
4848

49-
return NSData(base64EncodedString: input + ending, options: NSDataBase64DecodingOptions(0))
49+
let base64 = input.stringByReplacingOccurrencesOfString("-", withString: "+", options: NSStringCompareOptions(0), range: nil)
50+
.stringByReplacingOccurrencesOfString("_", withString: "/", options: NSStringCompareOptions(0), range: nil) + ending
51+
52+
return NSData(base64EncodedString: base64, options: NSDataBase64DecodingOptions(0))
5053
}
5154

5255
func load(jwt:String) -> LoadResult {

0 commit comments

Comments
 (0)