webcrypto 套件為 Flutter 提供跨平台的 Web Cryptography API 實作,可在 Android、iOS、Web、macOS、Windows 及 Linux 上執行安全的加密運算,例如金鑰產生、加密、解密與數位簽章。此套件提供一致的介面,類似於瀏覽器端的 Web Crypto API,讓在 Flutter 應用程式中實作安全資料處理更為輕鬆。對於需要強大安全功能卻不需撰寫平台特定程式碼的應用程式而言,此套件特別實用。該套件由 Google 維護,並在 GitHub 上開源。
適用情境
安全數據加密
數位簽章驗證
密鑰管理
跨平台加密
安全的令牌處理
主要特色
跨平台相容性
符合 Web Crypto API 標準
支援對稱和非對稱加密
開源並由 Google 維護
無需原生程式碼
適合對象
需要安全資料儲存的應用程式
認證系統
安全通訊協議
注重隱私的應用程式
熟悉 Web Crypto API 的開發人員
使用建議
需要理解密碼學概念
不適合高性能量化加密密集型工作負載
依賴於 Dart 的非同步模型
僅限標準 Web Crypto 算法
可能需要額外的驗證才能用於生產環境
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
Cross-Platform Web Cryptography Implementation
This package provides a cross-platform implementation of the
Web Cryptography API.
Disclaimer: This is not an officially supported Google product.
This packages provides an implementation of the
Web Cryptography API across multiple platforms. Outside the
browser, this package features a native implementation embedding
BoringSSL using dart:ffi. When used inside a
web browser this package wraps the window.crypto APIs and
providing the same Dart API as the native implementation.
This way, package:webcrypto provides the same crypto API on Android, iOS, Web, Windows, Linux and Mac.
BoringSSL, Chrome and Firefox implementations pass the same test cases.
Missing:
Exceptions and errors thrown for invalid input is not tested yet.
The native implementation executes on the main-thread, however, all expensive
APIs are asynchronous, so they can be offloaded in the future.
For a discussion of the API design of this package,
see doc/design-rationale-md.
System dependencies
When you have a dependency on package:webcrypto, it will use
hooks to build BoringSSL. Thus, your system
must have:
cmake, and,
a C compiler (like gcc or clang)
Limitations
This package has a few limitations compared to the
Web Cryptography API. For a discussion of parity with
Web Cryptography APIs see doc/webcrypto-parity.md.
deriveKey is not supported, however, keys can always be created from
derivedBits which is supported.
wrapKey is not supported, however, keys can be exported and encrypted.
unwrapKey is not supported, however, keys can be decrypted and imported.
AES-KW is not supported because it does not support encrypt/decrypt.
Compatibility notes
This package has many tests cases to asses compatibility across the native
implementation using BoringSSL and various browser implementations of the
Web Cryptography APIs.
At the moment compatibility testing is limited to native implementation,
Chrome, Firefox and Safari.
Known Issues:
Chrome and BoringSSL does not support valid ECDH spki-formatted keys exported
by Firefox prior to version 72.
Firefox does not support PKCS8 import/export for ECDSA and ECDH keys.
Firefox does not handle counter wrap around for AES-CTR.
Safari does not support P-521 for ECDSA and ECDH.
The browser implementation of streaming methods for encryption,
decryption, signing and verification buffers the entire input, because
window.crypto does not expose a streaming API. However, the native
implementation using BoringSSL does support streaming.
In browsers, operations backed by window.crypto.subtle require a secure
context. When loaded from an insecure context, package:webcrypto throws
UnsupportedError for those operations with guidance to use HTTPS or a
trustworthy local origin such as localhost. fillRandomBytes() continues
to work because it uses window.crypto.getRandomValues(), which browsers
expose outside secure contexts.