Address SYSLIB0021 warning

Applies from net6.0 onwards, but can be fixed already
This commit is contained in:
Archi 2021-07-04 16:02:16 +02:00
parent 5405ce7f8b
commit c3c1eb8295
No known key found for this signature in database
GPG key ID: 6B138B4C64555AEA
3 changed files with 5 additions and 5 deletions

View file

@ -398,11 +398,11 @@ namespace ArchiSteamFarm.Core {
string networkGroupText = "";
if (!string.IsNullOrEmpty(Program.NetworkGroup)) {
using SHA256CryptoServiceProvider hashingAlgorithm = new();
using SHA256 hashingAlgorithm = SHA256.Create();
networkGroupText = "-" + BitConverter.ToString(hashingAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(Program.NetworkGroup!))).Replace("-", "", StringComparison.Ordinal);
} else if (!string.IsNullOrEmpty(GlobalConfig.WebProxyText)) {
using SHA256CryptoServiceProvider hashingAlgorithm = new();
using SHA256 hashingAlgorithm = SHA256.Create();
networkGroupText = "-" + BitConverter.ToString(hashingAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(GlobalConfig.WebProxyText!))).Replace("-", "", StringComparison.Ordinal);
}

View file

@ -106,7 +106,7 @@ namespace ArchiSteamFarm.Core {
// The only purpose of using hashingAlgorithm here is to cut on a potential size of the resource name - paths can be really long, and we almost certainly have some upper limit on the resource name we can allocate
// At the same time it'd be the best if we avoided all special characters, such as '/' found e.g. in base64, as we can't be sure that it's not a prohibited character in regards to native OS implementation
// Because of that, SHA256 is sufficient for our case, as it generates alphanumeric characters only, and is barely 256-bit long. We don't need any kind of complex cryptography or collision detection here, any hashing algorithm will do, and the shorter the better
using (SHA256CryptoServiceProvider hashingAlgorithm = new()) {
using (SHA256 hashingAlgorithm = SHA256.Create()) {
uniqueName = "Global\\" + GetOsResourceName(nameof(SingleInstance)) + "-" + BitConverter.ToString(hashingAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(Directory.GetCurrentDirectory()))).Replace("-", "", StringComparison.Ordinal);
}

View file

@ -2908,9 +2908,9 @@ namespace ArchiSteamFarm.Steam {
fileStream.Seek(0, SeekOrigin.Begin);
#pragma warning disable CA5350 // This is actually a fair warning, but there is nothing we can do about Steam using weak cryptographic algorithms
using SHA1CryptoServiceProvider sha = new();
using SHA1 hashingAlgorithm = SHA1.Create();
sentryHash = await sha.ComputeHashAsync(fileStream).ConfigureAwait(false);
sentryHash = await hashingAlgorithm.ComputeHashAsync(fileStream).ConfigureAwait(false);
#pragma warning restore CA5350 // This is actually a fair warning, but there is nothing we can do about Steam using weak cryptographic algorithms
}
} catch (Exception e) {