@@ -13,22 +13,7 @@ public static Guid GenerateJobTypeId(string queueName)
1313 {
1414 var key = GenerateJobTypeName ( queueName ) ;
1515
16- if ( CryptoConfig . AllowOnlyFipsAlgorithms )
17- {
18- using var hasher = SHA256 . Create ( ) ;
19-
20- var data = hasher . ComputeHash ( Encoding . UTF8 . GetBytes ( key ) ) ;
21-
22- return new Guid ( new ReadOnlySpan < byte > ( data , 0 , 16 ) . ToArray ( ) ) ;
23- }
24- else
25- {
26- using var hasher = MD5 . Create ( ) ;
27-
28- var data = hasher . ComputeHash ( Encoding . UTF8 . GetBytes ( key ) ) ;
29-
30- return new Guid ( data ) ;
31- }
16+ return JobMetadataCache . GenerateHashGuid ( key ) ;
3217 }
3318
3419 public static string GenerateJobTypeName ( string queueName )
@@ -50,7 +35,31 @@ public static Guid GenerateRecurringJobId(string jobName)
5035 {
5136 var key = GenerateJobTypeName ( jobName ) ;
5237
53- if ( CryptoConfig . AllowOnlyFipsAlgorithms )
38+ return JobMetadataCache . GenerateHashGuid ( key ) ;
39+ }
40+
41+ public static string GenerateJobTypeName ( string jobName )
42+ {
43+ var jobTypeName = TypeCache < TJob > . ShortName ;
44+
45+ var name = $ "{ jobTypeName } :{ jobName } ";
46+
47+ return name ;
48+ }
49+ }
50+
51+
52+ static class JobMetadataCache
53+ {
54+ static bool ? _fipsMode ;
55+
56+ public static bool IsFipsMode =>
57+ CryptoConfig . AllowOnlyFipsAlgorithms ||
58+ ( _fipsMode ??= bool . TryParse ( Environment . GetEnvironmentVariable ( "MT_FIPS_ENABLE" ) , out var fipsMode ) && fipsMode ) ;
59+
60+ public static Guid GenerateHashGuid ( string key )
61+ {
62+ if ( IsFipsMode )
5463 {
5564 using var hasher = SHA256 . Create ( ) ;
5665
@@ -67,14 +76,5 @@ public static Guid GenerateRecurringJobId(string jobName)
6776 return new Guid ( data ) ;
6877 }
6978 }
70-
71- public static string GenerateJobTypeName ( string jobName )
72- {
73- var jobTypeName = TypeCache < TJob > . ShortName ;
74-
75- var name = $ "{ jobTypeName } :{ jobName } ";
76-
77- return name ;
78- }
7979 }
8080}
0 commit comments