Skip to content

Commit ea1257e

Browse files
Use Convert.ToHexStringLower() (#56235)
Use `Convert.ToHexStringLower()` instead of looping through the buffer to format with a `StringBuilder`.
1 parent 2968716 commit ea1257e

File tree

2 files changed

+2
-21
lines changed

2 files changed

+2
-21
lines changed

src/Antiforgery/src/Internal/BinaryBlob.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Diagnostics;
5-
using System.Globalization;
65
using System.Runtime.CompilerServices;
76
using System.Security.Cryptography;
8-
using System.Text;
97

108
namespace Microsoft.AspNetCore.Antiforgery;
119

@@ -45,18 +43,7 @@ public int BitLength
4543
}
4644
}
4745

48-
private string DebuggerString
49-
{
50-
get
51-
{
52-
var sb = new StringBuilder("0x", 2 + (_data.Length * 2));
53-
for (var i = 0; i < _data.Length; i++)
54-
{
55-
sb.AppendFormat(CultureInfo.InvariantCulture, "{0:x2}", _data[i]);
56-
}
57-
return sb.ToString();
58-
}
59-
}
46+
private string DebuggerString => $"0x{Convert.ToHexStringLower(_data)}";
6047

6148
public override bool Equals(object? obj)
6249
{

src/Security/Authentication/Facebook/src/FacebookHandler.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.Globalization;
54
using System.Net.Http;
65
using System.Security.Claims;
76
using System.Security.Cryptography;
@@ -70,12 +69,7 @@ private string GenerateAppSecretProof(string accessToken)
7069
var key = Encoding.ASCII.GetBytes(Options.AppSecret);
7170
var tokenBytes = Encoding.ASCII.GetBytes(accessToken);
7271
var hash = HMACSHA256.HashData(key, tokenBytes);
73-
var builder = new StringBuilder();
74-
for (int i = 0; i < hash.Length; i++)
75-
{
76-
builder.Append(CultureInfo.InvariantCulture, $"{hash[i]:x2}");
77-
}
78-
return builder.ToString();
72+
return Convert.ToHexStringLower(hash);
7973
}
8074

8175
/// <inheritdoc />

0 commit comments

Comments
 (0)