File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Text ;
3
+ using FluentAssertions ;
4
+ using IdentityModel ;
5
+ using IdentityModel . OidcClient ;
6
+ using Xunit ;
7
+
8
+ public class CryptoHelperTests
9
+ {
10
+ [ Theory ]
11
+ [ InlineData ( "asdf" , "RS256" ) ]
12
+ [ InlineData ( "asdf" , "RS384" ) ]
13
+ [ InlineData ( "asdf" , "RS512" ) ]
14
+ public void ComputeHash_should_compute_correct_hashes_for_all_signature_algorithms ( string data , string algorithmName )
15
+ {
16
+ var sut = new CryptoHelper ( new OidcClientOptions ( ) ) ;
17
+ var algorithm = sut . GetMatchingHashAlgorithm ( algorithmName ) ;
18
+
19
+ var hash = algorithm . ComputeHash ( Encoding . ASCII . GetBytes ( data ) ) ;
20
+
21
+ var bytesInLeftHalf = algorithm . HashSize / 16 ; // Divide by 8 for bytes and then 2 to get just half.
22
+
23
+ var leftHalf = new byte [ bytesInLeftHalf ] ;
24
+ Array . Copy ( hash , leftHalf , bytesInLeftHalf ) ;
25
+
26
+ var hashString = Base64Url . Encode ( leftHalf ) ;
27
+
28
+ sut . ValidateHash ( data , hashString , algorithmName ) . Should ( ) . BeTrue ( ) ;
29
+ }
30
+
31
+ }
You can’t perform that action at this time.
0 commit comments