diff --git a/library/security/jwt/src/jwt_encoder.e b/library/security/jwt/src/jwt_encoder.e index 0dffce81..9c81ece3 100644 --- a/library/security/jwt/src/jwt_encoder.e +++ b/library/security/jwt/src/jwt_encoder.e @@ -266,11 +266,10 @@ feature {NONE} -- Implementation base64_hmacsha256 (s: READABLE_STRING_8; a_secret: READABLE_STRING_8): STRING_8 local - hs256: HMAC_SHA256 + ut: JWT_UTILITIES do - create hs256.make_ascii_key (a_secret) - hs256.update_from_string (s) - Result := hs256.base64_digest --lowercase_hexadecimal_string_digest + create ut + Result := ut.base64_hmacsha256 (s, a_secret) end end diff --git a/library/security/jwt/src/jwt_utilities.e b/library/security/jwt/src/jwt_utilities.e index e7bf4547..24eb5cc9 100644 --- a/library/security/jwt/src/jwt_utilities.e +++ b/library/security/jwt/src/jwt_utilities.e @@ -61,7 +61,33 @@ feature -- Encoding do create hs256.make_ascii_key (a_secret) hs256.update_from_string (s) - Result := hs256.base64_digest --lowercase_hexadecimal_string_digest + -- if Version >= EiffelStudio 17.11 then + -- Result := hs256.base64_digest --lowercase_hexadecimal_string_digest + -- else + Result := base64_bytes_encoded_string (hs256.digest) + -- end + end + +feature {NONE} -- Implementation + + base64_bytes_encoded_string (a_bytes: SPECIAL [NATURAL_8]): STRING_8 + -- Base64 string from `a_bytes`. + --| Note: to be removed when 17.11 is not latest release anymore. + local + s: STRING + i,n: INTEGER + do + from + i := 1 + n := a_bytes.count + create s.make (n) + until + i > n + loop + s.append_code (a_bytes[i - 1]) + i := i + 1 + end + Result := (create {BASE64}).encoded_string (s) end feature -- Decoding