Share via


Blazor WebAssembly 不支援 System.Security.Cryptography API

在瀏覽器中執行時,System.Security.Cryptography API 會在執行時間擲回 PlatformNotSupportedException

變更描述

在舊的 .NET 版本中,Blazor WebAssembly 應用程式無法使用大部分的 System.Security.Cryptography API。 從 .NET 5 開始,Blazor WebAssembly 應用程式會以完整的 .NET 5 API 介面區為目標,不過,由於瀏覽器沙箱限制,不支援所有 .NET 5 API。 在 .NET 5 和更新版本中,不支援 System.Security.Cryptography 的 API 會在 WebAssembly 上執行時擲回 PlatformNotSupportedException

提示

當您建置支援瀏覽器平台的專案時,平台相容性分析器會標示對受影響 API 的任何呼叫。 此分析器預設會在 .NET 5 和更新版本中執行。

變更原因

Microsoft 無法在 Blazor WebAssembly 設定中以相依性的形式寄送 OpenSSL。 我們嘗試與瀏覽器的 SubtleCrypto API 整合,嘗試解決此問題。 可惜的是,這需要重大的 API 變更,使它變得太難整合。

導入的版本

5.0

目前沒有建議的良好因應措施。

受影響的 API

除了下列各項之外的所有 System.Security.Cryptography API:

  • System.Security.Cryptography.RandomNumberGenerator
  • System.Security.Cryptography.IncrementalHash
  • System.Security.Cryptography.SHA1
  • System.Security.Cryptography.SHA256
  • System.Security.Cryptography.SHA384
  • System.Security.Cryptography.SHA512
  • System.Security.Cryptography.SHA1Managed
  • System.Security.Cryptography.SHA256Managed
  • System.Security.Cryptography.SHA384Managed
  • System.Security.Cryptography.SHA512Managed