diff --git a/src/Libraries/Microsoft.Extensions.AI.Abstractions/Utilities/AIJsonUtilities.cs b/src/Libraries/Microsoft.Extensions.AI.Abstractions/Utilities/AIJsonUtilities.cs index 80daa0ed7bc..51459193923 100644 --- a/src/Libraries/Microsoft.Extensions.AI.Abstractions/Utilities/AIJsonUtilities.cs +++ b/src/Libraries/Microsoft.Extensions.AI.Abstractions/Utilities/AIJsonUtilities.cs @@ -90,7 +90,7 @@ public static string HashDataToString(ReadOnlySpan values, JsonSerializ // For cases where the hash may be used as a cache key, we rely on collision resistance for security purposes. // If a collision occurs, we'd serve a cached LLM response for a potentially unrelated prompt, leading to information - // disclosure. Use of SHA256 is an implementation detail and can be easily swapped in the future if needed, albeit + // disclosure. Use of SHA384 is an implementation detail and can be easily swapped in the future if needed, albeit // invalidating any existing cache entries. #if NET IncrementalHashStream? stream = IncrementalHashStream.ThreadStaticInstance; @@ -107,7 +107,7 @@ public static string HashDataToString(ReadOnlySpan values, JsonSerializ stream = new(); } - Span hashData = stackalloc byte[SHA256.HashSizeInBytes]; + Span hashData = stackalloc byte[SHA384.HashSizeInBytes]; try { foreach (object? value in values) @@ -133,8 +133,8 @@ public static string HashDataToString(ReadOnlySpan values, JsonSerializ JsonSerializer.Serialize(stream, value, jti); } - using var sha256 = SHA256.Create(); - var hashData = sha256.ComputeHash(stream.GetBuffer(), 0, (int)stream.Length); + using var hashAlgorithm = SHA384.Create(); + var hashData = hashAlgorithm.ComputeHash(stream.GetBuffer(), 0, (int)stream.Length); return ConvertToHexString(hashData); @@ -185,7 +185,7 @@ private sealed class IncrementalHashStream : Stream public static IncrementalHashStream? ThreadStaticInstance; /// The used by this instance. - private readonly IncrementalHash _hash = IncrementalHash.CreateHash(HashAlgorithmName.SHA256); + private readonly IncrementalHash _hash = IncrementalHash.CreateHash(HashAlgorithmName.SHA384); /// Gets the current hash and resets. public void GetHashAndReset(Span bytes) => _hash.GetHashAndReset(bytes);