Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions GameFrameX.Foundation.Hash/Md5Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
// Official Documentation: https://gameframex.doc.alianblank.com/
// ==========================================================================================

using System.Diagnostics.CodeAnalysis;
using System.Security.Cryptography;
using System.Text;

Expand Down Expand Up @@ -62,6 +63,7 @@ public static class Md5Helper
/// <param name="isUpper">是否返回大写形式的哈希值,默认为false返回小写 / Whether to return uppercase hash, defaults to false for lowercase</param>
/// <returns>32个字符的十六进制字符串形式的哈希值 / A 32-character hexadecimal string hash value</returns>
/// <exception cref="ArgumentNullException">当 <paramref name="input"/> 为 null 时抛出 / Thrown when <paramref name="input"/> is null</exception>
[SuppressMessage("Sonar Code Smell", "S4790:Use a stronger hashing algorithm", Justification = "MD5 is intentionally used here for non-cryptographic checksum / fingerprint / cache-key scenarios; for security-sensitive use cases call Sha256Helper instead.")]
public static string Hash(string input, bool isUpper = false)
{
ArgumentNullException.ThrowIfNull(input, nameof(input));
Expand Down Expand Up @@ -104,6 +106,7 @@ public static string HashWithSalt(string input, string salt, bool isUpper = fals
/// <param name="isUpper">是否返回大写形式的哈希值,默认为false返回小写 / Whether to return uppercase hash, defaults to false for lowercase</param>
/// <returns>32个字符的十六进制字符串形式的哈希值 / A 32-character hexadecimal string hash value</returns>
/// <exception cref="ArgumentNullException">当 <paramref name="input"/> 或 <paramref name="salt"/> 为 null 时抛出 / Thrown when <paramref name="input"/> or <paramref name="salt"/> is null</exception>
[SuppressMessage("Sonar Code Smell", "S4790:Use a stronger hashing algorithm", Justification = "MD5 is intentionally used here for non-cryptographic checksum / fingerprint / cache-key scenarios; for security-sensitive use cases call Sha256Helper instead.")]
public static string HashWithSalt(string input, byte[] salt, bool isUpper = false)
{
ArgumentNullException.ThrowIfNull(input, nameof(input));
Expand All @@ -130,6 +133,7 @@ public static string HashWithSalt(string input, byte[] salt, bool isUpper = fals
/// <param name="isUpper">是否返回大写形式的哈希值,默认为false返回小写 / Whether to return uppercase hash, defaults to false for lowercase</param>
/// <returns>32个字符的十六进制字符串形式的哈希值 / A 32-character hexadecimal string hash value</returns>
/// <exception cref="ArgumentNullException">当 <paramref name="input"/> 为 null 时抛出 / Thrown when <paramref name="input"/> is null</exception>
[SuppressMessage("Sonar Code Smell", "S4790:Use a stronger hashing algorithm", Justification = "MD5 is intentionally used here for non-cryptographic checksum / fingerprint / cache-key scenarios; for security-sensitive use cases call Sha256Helper instead.")]
public static string Hash(byte[] input, bool isUpper = false)
{
ArgumentNullException.ThrowIfNull(input, nameof(input));
Expand All @@ -149,6 +153,7 @@ public static string Hash(byte[] input, bool isUpper = false)
/// <param name="input">要计算哈希值的流,不能为null / The stream to compute the hash for, cannot be null</param>
/// <returns>32个字符的十六进制字符串形式的哈希值 / A 32-character hexadecimal string hash value</returns>
/// <exception cref="ArgumentNullException">当 <paramref name="input"/> 为 null 时抛出 / Thrown when <paramref name="input"/> is null</exception>
[SuppressMessage("Sonar Code Smell", "S4790:Use a stronger hashing algorithm", Justification = "MD5 is intentionally used here for non-cryptographic checksum / fingerprint / cache-key scenarios; for security-sensitive use cases call Sha256Helper instead.")]
public static string Hash(Stream input)
{
ArgumentNullException.ThrowIfNull(input, nameof(input));
Expand All @@ -163,6 +168,7 @@ public static string Hash(Stream input)
/// <param name="input">要计算哈希值的流 / The stream to compute the hash for</param>
/// <param name="cancellationToken">用于取消异步操作的令牌 / Token used to cancel the asynchronous operation</param>
/// <returns>小写十六进制字符串形式的哈希值 / The lowercase hexadecimal hash value</returns>
[SuppressMessage("Sonar Code Smell", "S4790:Use a stronger hashing algorithm", Justification = "MD5 is intentionally used here for non-cryptographic checksum / fingerprint / cache-key scenarios; for security-sensitive use cases call Sha256Helper instead.")]
public static async Task<string> HashAsync(Stream input, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(input, nameof(input));
Expand Down