MD5 2.4.0
dotnet add package MD5 --version 2.4.0
NuGet\Install-Package MD5 -Version 2.4.0
<PackageReference Include="MD5" Version="2.4.0" />
<PackageVersion Include="MD5" Version="2.4.0" />
<PackageReference Include="MD5" />
paket add MD5 --version 2.4.0
#r "nuget: MD5, 2.4.0"
#:package MD5@2.4.0
#addin nuget:?package=MD5&version=2.4.0
#tool nuget:?package=MD5&version=2.4.0
MD5
Overview
MD5 is a .NET library that provides methods to generate MD5 hash from string, byteArray, object or stream content. It uses the System.Security.Cryptography.MD5 class to generate the hash.
Usage
To use the library, you can call the GetMD5 method on a string, byteArray, object or stream to get the MD5 hash.
Examples:
string hash1 = "hello world".GetMD5();
// or specific encoding type
string hash2 = "hello world".GetMD5(EncodingType.UTF8);
var stream = File.OpenRead("Rondonia.pdf");
string hash = stream.GetMD5();
byte[] byteArray = Encoding.UTF8.GetBytes("Hello, World!");
string hash = byteArray.GetMD5();
BrasilModel obj = new BrasilModel() { Id = 1, Details = "Maior país da América do Sul" };
string hash = obj.GetMD5();
For a number, you can use:
string hash = myNumber.ToString().GetMD5();
SHA-256 and HMAC-SHA-256
For new integrity scenarios, use the new GetSHA256 and GetHMACSHA256 methods. They are additional APIs and do not change the existing MD5 method signatures or their historical behavior.
SHA-256 is appropriate for public checksums, fingerprints and content integrity. HMAC-SHA-256 is appropriate when integrity and authenticity depend on a shared secret key. HMAC is not a password-hashing function; use the password-specific APIs below for passwords.
The new methods support strings, byte arrays, objects and streams, just like the existing MD5 methods. String and object inputs use UTF-8 by default.
string sha256 = "hello world".GetSHA256();
string secretKey = "a-secret-key";
string hmac = "hello world".GetHMACSHA256(secretKey);
For binary data and keys:
byte[] payload = Encoding.UTF8.GetBytes("Hello, World!");
byte[] key = Encoding.UTF8.GetBytes("a-secret-key");
string sha256 = payload.GetSHA256();
string hmac = payload.GetHMACSHA256(key);
Password hashing: PBKDF2, bcrypt and Argon2id
For password storage and authentication, use PasswordHash. These algorithms are deliberately separate from the legacy MD5 and salted-MD5 methods. Each Hash... method generates a random salt and returns a self-contained encoded value with the parameters required by its matching Verify... method.
Argon2id is the preferred choice for new password storage when the deployment environment supports it. PBKDF2-HMAC-SHA256 is a broadly compatible alternative, and bcrypt is useful when compatibility with existing bcrypt hashes is required.
string pbkdf2 = PasswordHash.HashPBKDF2("my password");
bool pbkdf2Matches = PasswordHash.VerifyPBKDF2("my password", pbkdf2);
string bcrypt = PasswordHash.HashBCrypt("my password");
bool bcryptMatches = PasswordHash.VerifyBCrypt("my password", bcrypt);
string argon2 = PasswordHash.HashArgon2("my password");
bool argon2Matches = PasswordHash.VerifyArgon2("my password", argon2);
Store the returned encoded value and verify the supplied password against it; never store the plaintext password. Password hashing is intentionally slower than a checksum, so tune the parameters for the production hardware and periodically review them. The existing GetMD5, GetMD5WithSalt, GetSHA256 and GetHMACSHA256 contracts and behavior are unchanged.
New Feature: MD5 with Salt
This feature generates the legacy salted MD5 variants supported by the package. A salt does not make MD5 suitable for password storage or authentication.
Usage
To use the salted hash functionality, you can call the GetMD5WithSalt method on a string, byte array, object or stream to get the legacy salted MD5 result.
The existing overloads intentionally retain their historical behavior for compatibility: string and object values hash salt + content, while byte arrays and streams hash content + salt. Do not change the order when reproducing hashes generated by older versions.
Examples:
string salt = "randomSalt";
string hash1 = "hello world".GetMD5WithSalt(salt);
// or specific encoding type
string hash2 = "hello world".GetMD5WithSalt(salt, EncodingType.UTF8);
byte[] byteArray = Encoding.UTF8.GetBytes("Hello, World!");
byte[] saltBytes = Encoding.UTF8.GetBytes("randomSalt");
string hash = byteArray.GetMD5WithSalt(saltBytes);
BrasilModel obj = new BrasilModel() { Id = 1, Details = "Maior país da América do Sul" };
string salt = "randomSalt";
string hash = obj.GetMD5WithSalt(salt);
For a number, you can use:
string salt = "randomSalt";
string hash = myNumber.ToString().GetMD5WithSalt(salt);
Installation
You can install the library via NuGet package manager by searching for MD5 or by executing the following command in the Package Manager Console:
PM> Install-Package MD5
License
This library is licensed under the MIT License. See the LICENSE file for more details.
Contributions
Contributions to this library are welcome. Please open an issue or submit a pull request with your changes.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- BCrypt.Net-Next (>= 4.2.0)
- Konscious.Security.Cryptography.Argon2 (>= 1.3.1)
- Newtonsoft.Json (>= 13.0.4)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MD5:
| Package | Downloads |
|---|---|
|
HashingTools
کتابخانهی قدرتمند و سبک برای هش کردن دادهها با الگوریتمهای متنوع. شامل الگوریتمهای MD5, SHA1, SHA256, bcrypt و Argon2. مناسب برای ذخیرهسازی امن پسوردها، بررسی یکپارچگی فایلها و تولید کلید. با پشتیبانی از Dependency Injection در پروژههای ASP.NET Core. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Added PBKDF2, bcrypt and Argon2id password-hashing APIs without changing existing MD5, SHA-256 or HMAC-SHA-256 signatures or behavior.