mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Use static DateTime.UnixEpoch and RandomNumberGenerator.Fill() (#18621)
This commit is contained in:
@@ -376,8 +376,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly DateTime s_epoch = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
/// <summary>
|
||||
/// This is more an implementation of the UNIX strftime.
|
||||
/// </summary>
|
||||
@@ -501,7 +499,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
break;
|
||||
|
||||
case 's':
|
||||
sb.Append(StringUtil.Format("{0:0}", dateTime.ToUniversalTime().Subtract(s_epoch).TotalSeconds));
|
||||
sb.Append(StringUtil.Format("{0:0}", dateTime.ToUniversalTime().Subtract(DateTime.UnixEpoch).TotalSeconds));
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
|
||||
@@ -1167,8 +1167,8 @@ namespace System.Management.Automation.Host
|
||||
// bytes of randomness (2^48 = 2.8e14) would take an attacker about 891 years to guess
|
||||
// a filename (assuming they knew the time the transcript was started).
|
||||
// (5 bytes = 3 years, 4 bytes = about a month)
|
||||
byte[] randomBytes = new byte[6];
|
||||
System.Security.Cryptography.RandomNumberGenerator.Create().GetBytes(randomBytes);
|
||||
Span<byte> randomBytes = stackalloc byte[6];
|
||||
System.Security.Cryptography.RandomNumberGenerator.Fill(randomBytes);
|
||||
string filename = string.Format(
|
||||
Globalization.CultureInfo.InvariantCulture,
|
||||
"PowerShell_transcript.{0}.{1}.{2:yyyyMMddHHmmss}.txt",
|
||||
|
||||
Reference in New Issue
Block a user