toJWK method

  1. @override
Map<String, dynamic> toJWK({
  1. String? keyID,
  2. RSAAlgorithm? algorithm,
})
override

Convert the key to a JWK JSON object representation

Implementation

@override
Map<String, dynamic> toJWK({String? keyID, RSAAlgorithm? algorithm}) {
  final e = key.publicExponent;
  if (e == null) throw ArgumentError('e is null');
  final n = key.modulus;
  if (n == null) throw ArgumentError('n is null');

  Map<String, dynamic> jwk = {
    'kty': 'RSA',
    'use': 'sig',
    'e': base64Unpadded(base64Url.encode(bigIntToBytes(e).reversed.toList())),
    'n': base64Unpadded(base64Url.encode(bigIntToBytes(n).reversed.toList())),
  };

  if (keyID != null) jwk['kid'] = keyID;
  if (algorithm != null) jwk['alg'] = algorithm.name;

  return jwk;
}