ECDSA Key Generation Fails on Mobile Web Browser
Closed this issue · 1 comments
cryptominingnews commented
Hi,
I'm getting the error "Expected a value of type 'String', but got one of type 'Null'" when generating an ECDSA key on a Mobile web browser (Chrome - Android). The same code works fine when running on a Desktop browser.
Steps
- Run a flutter app for web.
$ flutter run -d web-server --web-port 8080 --web-hostname 0.0.0.0
- Navigate to the app on a connected physical device.
http://<YOUR_IP_ADDRESS>:8080
- Generate key (throws error).
final keypair = await EcdsaPrivateKey.generateKey(EllipticCurve.p256);
Error
errors.dart:266 Uncaught (in promise) Error: Expected a value of type 'String', but got one of type 'Null'
at Object.throw_ [as throw] (errors.dart:266:49)
at Object.castError (errors.dart:99:3)
at Object.cast [as as] (operations.dart:485:10)
at String.as (core_patch.dart:719:17)
at Object.getProperty (js_util_patch.dart:60:5)
at get message [as message] (crypto_subtle.dart:125:25)
at Object._translateDomException (impl_js.utils.dart:58:18)
at _handleDomException (impl_js.utils.dart:113:11)
at _handleDomException.throw (<anonymous>)
at async_patch.dart:60:31
at _RootZone.runBinary (zone.dart:1665:54)
at _FutureListener.thenAwait.handleError (future_impl.dart:162:22)
at handleError (future_impl.dart:779:46)
at _Future._propagateToListeners (future_impl.dart:800:13)
at [_completeError] (future_impl.dart:575:5)
at async._AsyncCallbackEntry.new.callback (future_impl.dart:666:7)
at Object._microtaskLoop (schedule_microtask.dart:40:11)
at _startMicrotaskLoop (schedule_microtask.dart:49:5)
at async_patch.dart:166:15
Thank you
cryptominingnews commented
This is not an issue with the package. The browser's crypto library is only provided in secure contexts. I solved the issue by running the application over HTTPS with the help of this comment.