Skip to content

Commit feaa625

Browse files
committed
implement security recommendations from code review
1 parent 0274173 commit feaa625

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

ServiceStack.Text/src/ServiceStack.Text/StreamExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,16 @@ public static byte[] ToMd5Bytes(this Stream stream)
472472
return System.Security.Cryptography.MD5.Create().ComputeHash(stream);
473473
}
474474

475+
/// <summary>
476+
/// Returns the MD5 hash of the stream as a hex string.
477+
/// Do not use for passwords, tokens, or signatures.
478+
/// </summary>
475479
public static string ToMd5Hash(this Stream stream) => ToMd5Bytes(stream).ToHex();
476480

481+
/// <summary>
482+
/// Returns the MD5 hash of the stream as a hex string.
483+
/// Do not use for passwords, tokens, or signatures.
484+
/// </summary>
477485
public static string ToMd5Hash(this byte[] bytes) =>
478486
System.Security.Cryptography.MD5.Create().ComputeHash(bytes).ToHex();
479487

ServiceStack/src/ServiceStack/Auth/SaltedHash.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,28 @@ public static string HexHash(HashAlgorithm hash, byte[] bytes)
9696
return bytes == null || bytes.Length == 0 ? null : _.ComputeHash(bytes).ToHex();
9797
}
9898

99+
/// <summary>
100+
/// Returns the SHA-1 hash of the string as a hex string.
101+
/// Do not use for passwords, tokens, or signatures.
102+
/// </summary>
99103
public static string ToSha1Hash(this string value) => HexHash(TextConfig.CreateSha(), value);
100104

105+
/// <summary>
106+
/// Returns the SHA-1 hash of the byte array as a hex string.
107+
/// Do not use for passwords, tokens, or signatures.
108+
/// </summary>
101109
public static byte[] ToSha1HashBytes(this byte[] bytes)
102110
{
103111
using var hash = TextConfig.CreateSha();
104112
return hash.ComputeHash(bytes);
105113
}
106114

107115
public static string ToSha256Hash(this string value) => HexHash(SHA256.Create(), value);
116+
117+
/// <summary>
118+
/// Returns the MD5 hash of the stream as a hex string.
119+
/// Do not use for passwords, tokens, or signatures.
120+
/// </summary>
108121
public static string ToMd5Hash(this string value) => HexHash(MD5.Create(), value);
109122

110123
public static byte[] ToSha256HashBytes(this byte[] bytes)

0 commit comments

Comments
 (0)