Skip to content

Commit de81bcf

Browse files
committed
Fix: use sha2
1 parent efde389 commit de81bcf

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/System.Net.IPNetwork/UniqueLocalAddress.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,15 @@ private static byte[] GenerateRandomGlobalId()
180180
/// <returns>40-bit Global ID as a byte array.</returns>
181181
private static byte[] GenerateGlobalIdFromMac(byte[] macAddress)
182182
{
183-
using var sha1 = SHA1.Create();
183+
using var sha2 = SHA256.Create();
184184
byte[] input = new byte[macAddress.Length + 8];
185185
Array.Copy(macAddress, 0, input, 0, macAddress.Length);
186186

187187
// Add current timestamp
188188
byte[] timestamp = BitConverter.GetBytes(DateTimeOffset.UtcNow.ToUnixTimeSeconds());
189189
Array.Copy(timestamp, 0, input, macAddress.Length, timestamp.Length);
190190

191-
byte[] hash = sha1.ComputeHash(input);
191+
byte[] hash = sha2.ComputeHash(input);
192192
byte[] globalId = new byte[5];
193193
Array.Copy(hash, 0, globalId, 0, 5);
194194
return globalId;
@@ -201,9 +201,9 @@ private static byte[] GenerateGlobalIdFromMac(byte[] macAddress)
201201
/// <returns>40-bit Global ID as a byte array.</returns>
202202
private static byte[] GenerateGlobalIdFromSeed(string seed)
203203
{
204-
using var sha1 = SHA1.Create();
204+
using var sha2 = SHA256.Create();
205205
byte[] seedBytes = Encoding.UTF8.GetBytes(seed);
206-
byte[] hash = sha1.ComputeHash(seedBytes);
206+
byte[] hash = sha2.ComputeHash(seedBytes);
207207
byte[] globalId = new byte[5];
208208
Array.Copy(hash, 0, globalId, 0, 5);
209209
return globalId;

0 commit comments

Comments
 (0)