Skip to content

Commit 0ba8959

Browse files
authored
Replace BitConverter.ToString with Convert.ToHexString where appropriate (PowerShell#19216)
1 parent 7b7e4c8 commit 0ba8959

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetHash.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ protected override void EndProcessing()
155155
{
156156
byte[] bytehash = ComputeHash(InputStream);
157157

158-
string hash = BitConverter.ToString(bytehash).Replace("-", string.Empty);
158+
string hash = Convert.ToHexString(bytehash);
159159
WriteHashResult(Algorithm, hash, string.Empty);
160160
}
161161
}
@@ -177,7 +177,7 @@ private bool ComputeFileHash(string path, out string hash)
177177
openfilestream = File.OpenRead(path);
178178
byte[] bytehash = ComputeHash(openfilestream);
179179

180-
hash = BitConverter.ToString(bytehash).Replace("-", string.Empty);
180+
hash = Convert.ToHexString(bytehash);
181181
}
182182
catch (FileNotFoundException ex)
183183
{

src/System.Management.Automation/security/CatalogHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ internal static string CalculateFileHash(string filePath, string hashAlgorithm)
457457
_cmdlet.ThrowTerminatingError(errorRecord);
458458
}
459459

460-
hashValue = BitConverter.ToString(hashBytes).Replace("-", string.Empty);
460+
hashValue = Convert.ToHexString(hashBytes);
461461
}
462462

463463
return hashValue;

src/System.Management.Automation/utils/PsUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ internal static byte[] ComputeHash(byte[] buffer)
523523
internal static string ComputeHash(string input)
524524
{
525525
byte[] hashBytes = ComputeHash(Encoding.UTF8.GetBytes(input));
526-
return BitConverter.ToString(hashBytes).Replace("-", string.Empty);
526+
return Convert.ToHexString(hashBytes);
527527
}
528528
}
529529

src/System.Management.Automation/utils/tracing/PSEtwLog.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ internal static void LogAnalyticVerbose(PSEventId id, PSOpcode opcode, PSTask ta
244244
{
245245
if (provider.IsEnabled(PSLevel.Verbose, keyword))
246246
{
247-
string payLoadData = BitConverter.ToString(fragmentData.blob, fragmentData.offset, fragmentData.length);
248-
payLoadData = string.Create(CultureInfo.InvariantCulture, $"0x{payLoadData.Replace("-", string.Empty)}");
247+
string payLoadData = Convert.ToHexString(fragmentData.blob, fragmentData.offset, fragmentData.length);
248+
payLoadData = string.Create(CultureInfo.InvariantCulture, $"0x{payLoadData}");
249249

250250
provider.WriteEvent(id, PSChannel.Analytic, opcode, PSLevel.Verbose, task, keyword,
251251
objectId, fragmentId, isStartFragment, isEndFragment, fragmentLength,

src/TypeCatalogGen/TypeCatalogGen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ private static string GetAssemblyStrongName(MetadataReader metadataReader)
256256
}
257257

258258
// Convert bytes to hex format strings in lower case.
259-
string publicKeyTokenString = BitConverter.ToString(publicKeyTokenBytes).Replace("-", string.Empty).ToLowerInvariant();
259+
string publicKeyTokenString = Convert.ToHexString(publicKeyTokenBytes).ToLowerInvariant();
260260
string strongAssemblyName = string.Create(CultureInfo.InvariantCulture, $"{asmName}, Version={asmVersion}, Culture={asmCulture}, PublicKeyToken={publicKeyTokenString}");
261261

262262
return strongAssemblyName;

0 commit comments

Comments
 (0)