Description
exportJsonWebKey() produces different JWK metadata depending on the backend.
The native FFI backend adds an algorithm-appropriate use value:
"enc" for encryption algorithms such as AES-GCM
"sig" for signing algorithms such as HMAC
The browser backend delegates to SubtleCrypto.exportKey(), removes key_ops and ext, and returns the result without adding use. Consequently, the same public API returns different JWK shapes on native and browser platforms.
Both outputs are valid JWKs because use is optional, but the backend-dependent result is observable and can break applications that persist, compare, validate, or route exported keys using this metadata.
Reproduction
import 'dart:typed_data';
import 'package:webcrypto/webcrypto.dart';
Future<void> main() async {
final aes = await AesGcmSecretKey.importRawKey(Uint8List(16));
final hmac = await HmacSecretKey.importRawKey(
Uint8List(32),
Hash.sha256,
);
print(await aes.exportJsonWebKey());
print(await hmac.exportJsonWebKey());
}
Native output includes:
{kty: oct, use: enc, alg: A128GCM, ...}
{kty: oct, use: sig, alg: HS256, ...}
Chrome output under both Dart2JS and Dart2Wasm omits use:
{kty: oct, alg: A128GCM, ...}
{kty: oct, alg: HS256, ...}
Expected behavior
exportJsonWebKey() should return consistent algorithm metadata across supported backends.
Suggested fix
Normalize browser JWK exports after SubtleCrypto.exportKey():
- add
"use": "enc" for AES and RSA-OAEP keys;
- add
"use": "sig" for HMAC, ECDSA, RSA-PSS, and RSASSA-PKCS1-v1_5 keys;
- continue omitting
use for ECDH;
- continue omitting
key_ops and ext, since configurable key capabilities are outside the current public API;
- add regression coverage for native, Dart2JS, and Dart2Wasm.
Description
exportJsonWebKey()produces different JWK metadata depending on the backend.The native FFI backend adds an algorithm-appropriate
usevalue:"enc"for encryption algorithms such as AES-GCM"sig"for signing algorithms such as HMACThe browser backend delegates to
SubtleCrypto.exportKey(), removeskey_opsandext, and returns the result without addinguse. Consequently, the same public API returns different JWK shapes on native and browser platforms.Both outputs are valid JWKs because
useis optional, but the backend-dependent result is observable and can break applications that persist, compare, validate, or route exported keys using this metadata.Reproduction
Native output includes:
Chrome output under both Dart2JS and Dart2Wasm omits
use:Expected behavior
exportJsonWebKey()should return consistent algorithm metadata across supported backends.Suggested fix
Normalize browser JWK exports after
SubtleCrypto.exportKey():"use": "enc"for AES and RSA-OAEP keys;"use": "sig"for HMAC, ECDSA, RSA-PSS, and RSASSA-PKCS1-v1_5 keys;usefor ECDH;key_opsandext, since configurable key capabilities are outside the current public API;