File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
src/CodeOfChaos.Extensions Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 33// ---------------------------------------------------------------------------------------------------------------------
44using System . Diagnostics ;
55using System . Diagnostics . CodeAnalysis ;
6+ using System . Security . Cryptography ;
7+ using System . Text ;
68
79// ReSharper disable once CheckNamespace
810namespace System ;
@@ -30,4 +32,16 @@ public static Guid ToGuid(this string input) {
3032 return Guid . Parse ( input ) ;
3133 #endif
3234 }
35+
36+ /// <summary>
37+ /// Converts a given string into a GUID by hashing it using the SHA256 algorithm.
38+ /// </summary>
39+ /// <param name="input">The input string to hash and convert into a GUID.</param>
40+ /// <returns>A <see cref="Guid"/> created from the hashed value of the input string.</returns>
41+ public static Guid ToGuidAsHashed ( this string input ) {
42+ byte [ ] hash = SHA256 . HashData ( Encoding . UTF8 . GetBytes ( input ) ) ;
43+
44+ // Use the first 16 bytes of the hash to create a GUID
45+ return new Guid ( hash . Take ( 16 ) . ToArray ( ) ) ;
46+ }
3347}
You can’t perform that action at this time.
0 commit comments