Skip to content

Commit

Permalink
feat: add support for base64 encoded secrets (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
JSosna authored Apr 25, 2024
1 parent c59770c commit adbd3b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/src/algorithms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/src/keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit adbd3b7

Please sign in to comment.