|
1 | 1 | package com.auth0.jwt; |
2 | 2 |
|
3 | | -import com.fasterxml.jackson.databind.JsonNode; |
4 | | -import com.fasterxml.jackson.databind.ObjectMapper; |
5 | | - |
6 | | -import org.apache.commons.codec.binary.Base64; |
7 | | - |
8 | | -import javax.crypto.Mac; |
9 | | -import javax.crypto.spec.SecretKeySpec; |
10 | | - |
11 | 3 | import java.io.IOException; |
12 | | -import java.io.UnsupportedEncodingException; |
13 | 4 | import java.nio.charset.Charset; |
14 | 5 | import java.security.InvalidKeyException; |
15 | 6 | import java.security.MessageDigest; |
16 | 7 | import java.security.NoSuchAlgorithmException; |
17 | 8 | import java.security.SignatureException; |
18 | | -import java.util.ArrayList; |
19 | | -import java.util.Arrays; |
20 | 9 | import java.util.HashMap; |
21 | 10 | import java.util.Map; |
22 | 11 |
|
| 12 | +import javax.crypto.Mac; |
| 13 | +import javax.crypto.spec.SecretKeySpec; |
| 14 | + |
| 15 | +import org.apache.commons.codec.binary.Base64; |
| 16 | + |
| 17 | +import com.fasterxml.jackson.databind.JsonNode; |
| 18 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 19 | + |
23 | 20 | /** |
24 | 21 | * JWT Java Implementation |
25 | 22 | * Adapted from https://bitbucket.org/lluisfaja/javajwt/wiki/Home |
@@ -119,7 +116,7 @@ void verifySignature(String[] pieces, String algorithm) throws NoSuchAlgorithmEx |
119 | 116 | hmac.init(new SecretKeySpec(secret, algorithm)); |
120 | 117 | byte[] sig = hmac.doFinal(new StringBuilder(pieces[0]).append(".").append(pieces[1]).toString().getBytes()); |
121 | 118 |
|
122 | | - if (!MessageDigest.isEqual(sig, decoder.decodeBase64(pieces[2]))) { |
| 119 | + if (!MessageDigest.isEqual(sig, decoder.decode(pieces[2]))) { |
123 | 120 | throw new SignatureException("signature verification failed"); |
124 | 121 | } |
125 | 122 | } |
@@ -173,7 +170,7 @@ String getAlgorithm(JsonNode jwtHeader) { |
173 | 170 | } |
174 | 171 |
|
175 | 172 | JsonNode decodeAndParse(String b64String) throws IOException { |
176 | | - String jsonString = new String(decoder.decodeBase64(b64String), "UTF-8"); |
| 173 | + String jsonString = new String(decoder.decode(b64String), "UTF-8"); |
177 | 174 | JsonNode jwtHeader = mapper.readValue(jsonString, JsonNode.class); |
178 | 175 | return jwtHeader; |
179 | 176 | } |
|
0 commit comments