mirror of
https://github.com/jonasroussel/dart_jsonwebtoken.git
synced 2025-08-06 13:51:08 +08:00
feat: add support for base64 encoded secrets (#54)
This commit is contained in:
@ -147,7 +147,12 @@ class HMACAlgorithm extends JWTAlgorithm {
|
|||||||
assert(key is SecretKey, 'key must be a SecretKey');
|
assert(key is SecretKey, 'key must be a SecretKey');
|
||||||
final secretKey = key as 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);
|
return Uint8List.fromList(hmac.convert(body).bytes);
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,9 @@ abstract class JWTKey {}
|
|||||||
/// For HMAC algorithms
|
/// For HMAC algorithms
|
||||||
class SecretKey extends JWTKey {
|
class SecretKey extends JWTKey {
|
||||||
String key;
|
String key;
|
||||||
|
bool isBase64Encoded;
|
||||||
|
|
||||||
SecretKey(this.key);
|
SecretKey(this.key, {this.isBase64Encoded = false});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For RSA algorithm, in sign method
|
/// For RSA algorithm, in sign method
|
||||||
|
Reference in New Issue
Block a user