feat: add support for base64 encoded secrets (#54)

This commit is contained in:
Jakub Sosna
2024-04-25 15:27:39 +02:00
committed by GitHub
parent c59770c06a
commit adbd3b7046
2 changed files with 8 additions and 2 deletions

View File

@ -147,7 +147,12 @@ class HMACAlgorithm extends JWTAlgorithm {
assert(key is SecretKey, 'key must be a SecretKey');
final secretKey = key as SecretKey;
final hmac = Hmac(_getHash(name), utf8.encode(secretKey.key));
final hmac = Hmac(
_getHash(name),
secretKey.isBase64Encoded
? base64Decode(secretKey.key)
: utf8.encode(secretKey.key),
);
return Uint8List.fromList(hmac.convert(body).bytes);
}