Blazor WebAssembly で System.Security.Cryptography API がサポートされない

System.Security.Cryptography API は、ブラウザーで実行されると、実行時に PlatformNotSupportedException をスローします。

変更内容

以前のバージョンの .NET では、ほとんどの System.Security.Cryptography API が Blazor WebAssembly で使用できません。 .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