diff --git a/lib/src/algorithms.dart b/lib/src/algorithms.dart index 7631238..e00eca3 100644 --- a/lib/src/algorithms.dart +++ b/lib/src/algorithms.dart @@ -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); } diff --git a/lib/src/keys.dart b/lib/src/keys.dart index 058a166..71d4597 100644 --- a/lib/src/keys.dart +++ b/lib/src/keys.dart @@ -11,8 +11,9 @@ abstract class JWTKey {} /// For HMAC algorithms class SecretKey extends JWTKey { String key; + bool isBase64Encoded; - SecretKey(this.key); + SecretKey(this.key, {this.isBase64Encoded = false}); } /// For RSA algorithm, in sign method