Blazor WebAssembly no soporta AES (System.Security.Cryptography) → obliga a usar librerías externas

Alberto Reyes Peralta 0 Reputation points
2025-12-04T20:01:00.27+00:00

Actualmente, en Blazor WebAssembly, el uso de System.Security.Cryptography.Aes falla con el error:

Algorithm 'Aes' is not supported on this platform.

Esto ocurre incluso con configuraciones básicas como:

using (Aes aesAlg = Aes.Create())

{

    aesAlg.Key = datosKey;

    aesAlg.Mode = CipherMode.ECB;

    var encryptor = aesAlg.CreateEncryptor(aesAlg.Key, null);

    ...

}

Mientras que en .NET Server funciona perfectamente.

Problema:

  • Blazor WASM no soporta AES nativo, ni siquiera CBC, lo que obliga a usar JavaScript interop con Web Crypto o librerías externas como CryptoJS.
  • Esto rompe la consistencia entre plataformas .NET y obliga a duplicar lógica.

Impacto:

  • No se puede implementar cifrado simétrico en C# puro en Blazor WASM.
  • Se pierde interoperabilidad y seguridad (ECB es inseguro, pero incluso CBC/GCM no están disponibles en C# en WASM).

Solicitud:

  • Agregar soporte completo para System.Security.Cryptography.Aes en Blazor WebAssembly, aprovechando Web Crypto internamente.
  • O al menos documentar claramente las limitaciones y ofrecer una API oficial para usar Web Crypto desde C# sin depender de JS interop manual.

Escenario real:

  • API REST usa AES para cifrar datos sensibles.
  • Cliente Blazor WASM necesita cifrar antes de enviar.
  • Hoy, la única opción es usar librerías externas (CryptoJS) o escribir JS interop manual.Mientras que en .NET Server funciona perfectamente. Problema:
    • Blazor WASM no soporta AES nativo, ni siquiera CBC, lo que obliga a usar JavaScript interop con Web Crypto o librerías externas como CryptoJS.
    • Esto rompe la consistencia entre plataformas .NET y obliga a duplicar lógica.
    Impacto:
    • No se puede implementar cifrado simétrico en C# puro en Blazor WASM.
    • Se pierde interoperabilidad y seguridad (ECB es inseguro, pero incluso CBC/GCM no están disponibles en C# en WASM).
    Solicitud:
    • Agregar soporte completo para System.Security.Cryptography.Aes en Blazor WebAssembly, aprovechando Web Crypto internamente.
    • O al menos documentar claramente las limitaciones y ofrecer una API oficial para usar Web Crypto desde C# sin depender de JS interop manual.
    Escenario real:
    • API REST usa AES para cifrar datos sensibles.
    • Cliente Blazor WASM necesita cifrar antes de enviar.
    • Hoy, la única opción es usar librerías externas (CryptoJS) o escribir JS interop manual.
Developer technologies | .NET | Blazor
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Q&A Assist
    2025-12-04T20:01:11.19+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Blazor WebAssembly does not support the System.Security.Cryptography.Aes class due to browser sandbox constraints. When attempting to use AES, you will encounter a PlatformNotSupportedException, indicating that the algorithm is not supported on this platform. This limitation is because Microsoft cannot ship OpenSSL as a dependency in the Blazor WebAssembly configuration, and attempts to integrate with the browser's SubtleCrypto API have not been successful.

    As a result, developers are required to use JavaScript interop with the Web Crypto API or external libraries like CryptoJS to implement symmetric encryption in Blazor WebAssembly applications. This situation can lead to inconsistencies between .NET platforms and necessitates duplicating logic across client and server applications.

    Currently, there are no good workarounds to implement AES directly in C# for Blazor WebAssembly, and the recommended approach is to utilize JavaScript interop for cryptographic operations.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.