@@ -38,7 +38,7 @@ public void shouldGetStringBytes() throws Exception {
3838 public void shouldPassHMAC256Verification () throws Exception {
3939 String jwt = "eyJhbGciOiJIUzI1NiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.mZ0m_N1J4PgeqWmi903JuUoDRZDBPB7HwkS4nVyWH1M" ;
4040 Algorithm algorithmString = Algorithm .HMAC256 ("secret" );
41- Algorithm algorithmBytes = Algorithm .HMAC256 ("secret" .getBytes ());
41+ Algorithm algorithmBytes = Algorithm .HMAC256 ("secret" .getBytes (StandardCharsets . UTF_8 ));
4242 AlgorithmUtils .verify (algorithmString , jwt );
4343 AlgorithmUtils .verify (algorithmBytes , jwt );
4444 }
@@ -57,15 +57,15 @@ public void shouldFailHMAC256VerificationWithInvalidSecretBytes() throws Excepti
5757 exception .expect (SignatureVerificationException .class );
5858 exception .expectMessage ("The Token's Signature resulted invalid when verified using the Algorithm: HmacSHA256" );
5959 String jwt = "eyJhbGciOiJIUzI1NiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.mZ0m_N1J4PgeqWmi903JuUoDRZDBPB7HwkS4nVyWH1M" ;
60- Algorithm algorithm = Algorithm .HMAC256 ("not_real_secret" .getBytes ());
60+ Algorithm algorithm = Algorithm .HMAC256 ("not_real_secret" .getBytes (StandardCharsets . UTF_8 ));
6161 AlgorithmUtils .verify (algorithm , jwt );
6262 }
6363
6464 @ Test
6565 public void shouldPassHMAC384Verification () throws Exception {
6666 String jwt = "eyJhbGciOiJIUzM4NCIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.uztpK_wUMYJhrRv8SV-1LU4aPnwl-EM1q-wJnqgyb5DHoDteP6lN_gE1xnZJH5vw" ;
6767 Algorithm algorithmString = Algorithm .HMAC384 ("secret" );
68- Algorithm algorithmBytes = Algorithm .HMAC384 ("secret" .getBytes ());
68+ Algorithm algorithmBytes = Algorithm .HMAC384 ("secret" .getBytes (StandardCharsets . UTF_8 ));
6969 AlgorithmUtils .verify (algorithmString , jwt );
7070 AlgorithmUtils .verify (algorithmBytes , jwt );
7171 }
@@ -84,15 +84,15 @@ public void shouldFailHMAC384VerificationWithInvalidSecretBytes() throws Excepti
8484 exception .expect (SignatureVerificationException .class );
8585 exception .expectMessage ("The Token's Signature resulted invalid when verified using the Algorithm: HmacSHA384" );
8686 String jwt = "eyJhbGciOiJIUzM4NCIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.uztpK_wUMYJhrRv8SV-1LU4aPnwl-EM1q-wJnqgyb5DHoDteP6lN_gE1xnZJH5vw" ;
87- Algorithm algorithm = Algorithm .HMAC384 ("not_real_secret" .getBytes ());
87+ Algorithm algorithm = Algorithm .HMAC384 ("not_real_secret" .getBytes (StandardCharsets . UTF_8 ));
8888 AlgorithmUtils .verify (algorithm , jwt );
8989 }
9090
9191 @ Test
9292 public void shouldPassHMAC512Verification () throws Exception {
9393 String jwt = "eyJhbGciOiJIUzUxMiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.VUo2Z9SWDV-XcOc_Hr6Lff3vl7L9e5Vb8ThXpmGDFjHxe3Dr1ZBmUChYF-xVA7cAdX1P_D4ZCUcsv3IefpVaJw" ;
9494 Algorithm algorithmString = Algorithm .HMAC512 ("secret" );
95- Algorithm algorithmBytes = Algorithm .HMAC512 ("secret" .getBytes ());
95+ Algorithm algorithmBytes = Algorithm .HMAC512 ("secret" .getBytes (StandardCharsets . UTF_8 ));
9696 AlgorithmUtils .verify (algorithmString , jwt );
9797 AlgorithmUtils .verify (algorithmBytes , jwt );
9898 }
@@ -111,7 +111,7 @@ public void shouldFailHMAC512VerificationWithInvalidSecretBytes() throws Excepti
111111 exception .expect (SignatureVerificationException .class );
112112 exception .expectMessage ("The Token's Signature resulted invalid when verified using the Algorithm: HmacSHA512" );
113113 String jwt = "eyJhbGciOiJIUzUxMiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.VUo2Z9SWDV-XcOc_Hr6Lff3vl7L9e5Vb8ThXpmGDFjHxe3Dr1ZBmUChYF-xVA7cAdX1P_D4ZCUcsv3IefpVaJw" ;
114- Algorithm algorithm = Algorithm .HMAC512 ("not_real_secret" .getBytes ());
114+ Algorithm algorithm = Algorithm .HMAC512 ("not_real_secret" .getBytes (StandardCharsets . UTF_8 ));
115115 AlgorithmUtils .verify (algorithm , jwt );
116116 }
117117
@@ -125,7 +125,7 @@ public void shouldThrowOnVerifyWhenSignatureAlgorithmDoesNotExists() throws Exce
125125 when (crypto .verifySignatureFor (anyString (), any (byte [].class ), any (byte [].class ), any (byte [].class )))
126126 .thenThrow (NoSuchAlgorithmException .class );
127127
128- Algorithm algorithm = new HMACAlgorithm (crypto , "some-alg" , "some-algorithm" , "secret" .getBytes ());
128+ Algorithm algorithm = new HMACAlgorithm (crypto , "some-alg" , "some-algorithm" , "secret" .getBytes (StandardCharsets . UTF_8 ));
129129 String jwt = "eyJhbGciOiJIUzI1NiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.mZ0m_N1J4PgeqWmi903JuUoDRZDBPB7HwkS4nVyWH1M" ;
130130 AlgorithmUtils .verify (algorithm , jwt );
131131 }
@@ -140,7 +140,7 @@ public void shouldThrowOnVerifyWhenTheSecretIsInvalid() throws Exception {
140140 when (crypto .verifySignatureFor (anyString (), any (byte [].class ), any (byte [].class ), any (byte [].class )))
141141 .thenThrow (InvalidKeyException .class );
142142
143- Algorithm algorithm = new HMACAlgorithm (crypto , "some-alg" , "some-algorithm" , "secret" .getBytes ());
143+ Algorithm algorithm = new HMACAlgorithm (crypto , "some-alg" , "some-algorithm" , "secret" .getBytes (StandardCharsets . UTF_8 ));
144144 String jwt = "eyJhbGciOiJIUzI1NiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.mZ0m_N1J4PgeqWmi903JuUoDRZDBPB7HwkS4nVyWH1M" ;
145145 AlgorithmUtils .verify (algorithm , jwt );
146146 }
0 commit comments