Skip to content

Commit 451bfd4

Browse files
committed
improve: using stackalloc for heap free allocation token generation
1 parent e5cfcef commit 451bfd4

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/KSFramework/Utilities/SecurityHelper.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ public static string GetSha256Hash(string input)
1616

1717
public static string GenerateToken(int byteLength = 32)
1818
{
19-
var randomNumber = new byte[byteLength];
20-
using var rng = RandomNumberGenerator.Create();
21-
rng.GetBytes(randomNumber);
19+
Span<byte> randomNumber = stackalloc byte[byteLength];
20+
RandomNumberGenerator.Fill(randomNumber);
2221
return Convert.ToBase64String(randomNumber);
2322
}
2423
}

0 commit comments

Comments
 (0)