Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 263978c

Browse files
committed
Fix at_hash calculation for RS384, RS512
1 parent a5e1176 commit 263978c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/OidcClient/CryptoHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public bool ValidateHash(string data, string hashedData, string signatureAlgorit
5656
using (hashAlgorithm)
5757
{
5858
var hash = hashAlgorithm.ComputeHash(Encoding.ASCII.GetBytes(data));
59-
var size = (hashAlgorithm.HashSize / 8) / 2;
59+
var size = hashAlgorithm.HashSize / 8 / 2; // Only take the left half of the data, as per spec for at_hash
6060

61-
byte[] leftPart = new byte[hashAlgorithm.HashSize / size];
62-
Array.Copy(hash, leftPart, hashAlgorithm.HashSize / size);
61+
byte[] leftPart = new byte[size];
62+
Array.Copy(hash, leftPart, size);
6363

6464
var leftPartB64 = Base64Url.Encode(leftPart);
6565
var match = leftPartB64.Equals(hashedData);

test/OidcClient.Tests/CryptoHelperTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void ComputeHash_should_compute_correct_hashes_for_all_signature_algorith
1818

1919
var hash = algorithm.ComputeHash(Encoding.ASCII.GetBytes(data));
2020

21-
var bytesInLeftHalf = algorithm.HashSize / 16; // Divide by 8 for bytes and then 2 to get just half.
21+
var bytesInLeftHalf = algorithm.HashSize / 16; // Divide by 8 for bytes and then 2 to get just half, as per spec for at_hash.
2222

2323
var leftHalf = new byte[bytesInLeftHalf];
2424
Array.Copy(hash, leftHalf, bytesInLeftHalf);

0 commit comments

Comments
 (0)