.NET 7 WebAssembly - Algorithm 'Aes' is not supported on this platform.
Description
.NET 7 enabled AES support on WebAssembly (See #42384 and #40074)
However it is still failing with the error:
Algorithm 'Aes' is not supported on this platform.
Reproduction Steps
- Create a Blazor WebAssembly App
- Run the following code (Anywhere):
using var aesAlg = Aes.Create();
var key = RandomNumberGenerator.GetBytes(aesAlg.KeySize / 8);
var iv = RandomNumberGenerator.GetBytes(aesAlg.BlockSize / 8);
aesAlg.CreateEncryptor(key, iv);
Expected behavior
No exception is thrown
Actual behavior
Exception is thrown when attempting to create encryptor. Stack trace:
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Algorithm 'Aes' is not supported on this platform. System.PlatformNotSupportedException: Algorithm 'Aes' is not supported on this platform. at System.Security.Cryptography.AesImplementation.CreateTransformCore(CipherMode cipherMode, PaddingMode paddingMode, Byte[] key, Byte[] iv, Int32 blockSize, Int32 paddingSize, Int32 feedback, Boolean encrypting) at System.Security.Cryptography.AesImplementation.CreateTransform(Byte[] rgbKey, Byte[] rgbIV, Boolean encrypting) at System.Security.Cryptography.AesImplementation.CreateEncryptor(Byte[] rgbKey, Byte[] rgbIV)
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
Support for the Aes class was removed from WASM in .NET 7 before it shipped. https://github.com/dotnet/runtime/issues/73858 has the details why.
If you need AES in blazor today, it is recommended that you use JS.InvokeAsync to interop with SubtleCrypto. This document has an example: https://github.com/dotnet/designs/blob/main/accepted/2021/blazor-wasm-crypto.md#blazor-wasm--js-interop-example
Though the document's example is for HMAC, the same concepts apply for AES.
Tagging subscribers to this area: @dotnet/area-system-security, @vcsjones See info in area-owners.md if you want to be subscribed.
Issue Details
Description
.NET 7 enabled AES support on WebAssembly (See #42384 and #40074)
However it is still failing with the error:
Algorithm 'Aes' is not supported on this platform.
Reproduction Steps
- Create a Blazor WebAssembly App
- Run the following code (Anywhere):
using var aesAlg = Aes.Create();
var key = RandomNumberGenerator.GetBytes(aesAlg.KeySize / 8);
var iv = RandomNumberGenerator.GetBytes(aesAlg.BlockSize / 8);
aesAlg.CreateEncryptor(key, iv);
Expected behavior
No exception is thrown
Actual behavior
Exception is thrown when attempting to create encryptor. Stack trace:
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Algorithm 'Aes' is not supported on this platform. System.PlatformNotSupportedException: Algorithm 'Aes' is not supported on this platform. at System.Security.Cryptography.AesImplementation.CreateTransformCore(CipherMode cipherMode, PaddingMode paddingMode, Byte[] key, Byte[] iv, Int32 blockSize, Int32 paddingSize, Int32 feedback, Boolean encrypting) at System.Security.Cryptography.AesImplementation.CreateTransform(Byte[] rgbKey, Byte[] rgbIV, Boolean encrypting) at System.Security.Cryptography.AesImplementation.CreateEncryptor(Byte[] rgbKey, Byte[] rgbIV)
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
| Author: | NullQubit |
|---|---|
| Assignees: | - |
| Labels: |
|
| Milestone: | - |
It seems that this question has been answered. I'm going to close this out, but please feel free to re-open if you feel there are any issues that still need to be addressed.