File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,10 +37,28 @@ public static byte[] HexadecimalStringToByteArray(this string input)
3737 }
3838 return output ;
3939 }
40+ /// <summary>
41+ /// Converts a string to its hexadecimal representation.
42+ /// </summary>
43+ /// <param name="input">The input string to convert.</param>
44+ /// <returns>The hexadecimal representation of the input string.</returns>
45+
46+ public static string ConvertToHexString ( this string input )
47+ {
48+ byte [ ] byteArray = Encoding . UTF8 . GetBytes ( input ) ;
49+ StringBuilder hexBuilder = new StringBuilder ( byteArray . Length * 2 ) ;
50+
51+ foreach ( byte b in byteArray )
52+ {
53+ hexBuilder . AppendFormat ( "{0:X2}" , b ) ;
54+ }
55+
56+ return hexBuilder . ToString ( ) ;
57+ }
4058
4159 public static byte [ ] ConvertKeysToBytes ( this string data )
4260 {
4361 return Encoding . UTF8 . GetBytes ( data ) ;
44- }
62+ }
4563 }
4664}
You can’t perform that action at this time.
0 commit comments