Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I use MD5 in Blazor WASM when it is deprecated?

In a .NET 8 console app, this code works:

using var hasher = MD5.Create();
var bytes = Encoding.UTF8.GetBytes("Hello world!");
var hashBytes = hasher.ComputeHash(bytes);
var hashHex = Convert.ToHexString(hashBytes);
Console.WriteLine(hashHex);
// Prints: 86FB269D190D2C85F6E0468CECA42A20

In Blazor WASM I get this error:

Error: One or more errors occurred. (‘MD5’ is not a known hash algorithm)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I found out MD5 is not recommended anymore but it is still used by the software library I need to work with. Any ideas? I am open to a Javascript MD5 library if required.

>Solution :

I have answered a similar question that answers this question here: Any .NET MD5 library (Nuget) for Blazor (WebAssembly)?

The code in that post is from the open source library Radzen. I modified it slightly to more align with the original MS implementation.

Example use:

var bytes = Encoding.UTF8.GetBytes("Hello world!");
var hashBytes = MD5.ComputeHash(bytes);
var hashHex = Convert.ToHexString(hashBytes);
Console.WriteLine(hashHex);
// 86FB269D190D2C85F6E0468CECA42A20
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading