|
4 | 4 | * for more information concerning the license and the contributors participating to this project.
|
5 | 5 | */
|
6 | 6 |
|
| 7 | +using System; |
7 | 8 | using System.Collections.Generic;
|
8 |
| -using System.Globalization; |
9 | 9 | using System.Net.Http;
|
10 | 10 | using System.Net.Http.Headers;
|
11 | 11 | using System.Security.Claims;
|
@@ -39,9 +39,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
|
39 | 39 | [NotNull] AuthenticationProperties properties,
|
40 | 40 | [NotNull] OAuthTokenResponse tokens)
|
41 | 41 | {
|
42 |
| - using var algorithm = HashAlgorithm.Create("MD5"); |
43 |
| - string accessSecret = GetHash(algorithm!, tokens.AccessToken + Options.ClientSecret); |
44 |
| - string sign = GetHash(algorithm!, $"application_key={Options.PublicSecret}format=jsonmethod=users.getCurrentUser{accessSecret}"); |
| 42 | + string accessSecret = GetMD5Hash(tokens.AccessToken + Options.ClientSecret); |
| 43 | + string sign = GetMD5Hash($"application_key={Options.PublicSecret}format=jsonmethod=users.getCurrentUser{accessSecret}"); |
45 | 44 |
|
46 | 45 | string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary<string, string?>
|
47 | 46 | {
|
@@ -77,16 +76,13 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
|
77 | 76 | return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
|
78 | 77 | }
|
79 | 78 |
|
80 |
| - private static string GetHash(HashAlgorithm algorithm, string input) |
| 79 | + private static string GetMD5Hash(string input) |
81 | 80 | {
|
82 |
| - var builder = new StringBuilder(); |
| 81 | +#pragma warning disable CA5351 |
| 82 | + byte[] hash = MD5.HashData(Encoding.UTF8.GetBytes(input)); |
| 83 | +#pragma warning restore CA5351 |
83 | 84 |
|
84 |
| - foreach (byte b in algorithm.ComputeHash(Encoding.UTF8.GetBytes(input))) |
85 |
| - { |
86 |
| - builder.Append(b.ToString("x2", CultureInfo.InvariantCulture)); |
87 |
| - } |
88 |
| - |
89 |
| - return builder.ToString(); |
| 85 | + return Convert.ToHexString(hash).ToLowerInvariant(); |
90 | 86 | }
|
91 | 87 | }
|
92 | 88 | }
|
0 commit comments