1- using System ;
1+ using System ;
22using System . Collections . Generic ;
33using System . Drawing ;
44using System . Globalization ;
1212using System . Text . RegularExpressions ;
1313using System . Threading ;
1414
15- namespace Qvoid_Authentication
15+ namespace Qvoid . Authentication
1616{
1717 public static class Encryption
1818 {
19- private static string GetHexString ( byte [ ] bt )
20- {
21- string s = string . Empty ;
22- for ( int i = 0 ; i < bt . Length ; i ++ )
23- {
24- byte b = bt [ i ] ;
25- int n , n1 , n2 ;
26- n = ( int ) b ;
27- n1 = n & 15 ;
28- n2 = ( n >> 4 ) & 15 ;
29- if ( n2 > 9 )
30- s += ( ( char ) ( n2 - 10 + ( int ) 'A' ) ) . ToString ( ) ;
31- else
32- s += n2 . ToString ( ) ;
33- if ( n1 > 9 )
34- s += ( ( char ) ( n1 - 10 + ( int ) 'A' ) ) . ToString ( ) ;
35- else
36- s += n1 . ToString ( ) ;
37- if ( ( i + 1 ) != bt . Length && ( i + 1 ) % 2 == 0 ) s += "-" ;
38- }
39- return s ;
40- }
19+ private static Random _random = new Random ( ) ;
4120
42- private static byte [ ] StringToByteArray ( string hex )
43- {
44- //Haha belongs to the Shabak
45- return ( from x in Enumerable . Range ( 0 , hex . Length )
46- where x % 2 == 0
47- select Convert . ToByte ( hex . Substring ( x , 2 ) , 16 ) ) . ToArray < byte > ( ) ;
48- }
21+ private static string GetHexString ( byte [ ] data ) => BitConverter . ToString ( data ) ;
22+
23+ private static byte [ ] StringToByteArray ( string hex ) => ( from x in Enumerable . Range ( 0 , hex . Length )
24+ where x % 2 == 0
25+ select Convert . ToByte ( hex . Substring ( x , 2 ) , 16 ) ) . ToArray < byte > ( ) ;
26+ public static string MD5 ( string Input ) => GetHexString ( new MD5CryptoServiceProvider ( ) . ComputeHash ( new ASCIIEncoding ( ) . GetBytes ( Input ) ) ) ;
4927
5028 public static string StrXOR ( string input , byte key , bool encrypt )
5129 {
@@ -163,28 +141,21 @@ public static string ComputeSha256Hash(string rawData)
163141 }
164142 }
165143
166- public static string MD5 ( string Input )
167- {
168- return GetHexString ( new MD5CryptoServiceProvider ( ) . ComputeHash ( new ASCIIEncoding ( ) . GetBytes ( Input ) ) ) ;
169- }
170144 public static string SHA256CheckSum ( string filePath )
171145 {
172146 using ( SHA256 SHA256 = SHA256Managed . Create ( ) )
173- {
174- using ( FileStream fileStream = File . OpenRead ( filePath ) )
175- return Convert . ToBase64String ( SHA256 . ComputeHash ( fileStream ) ) ;
176- }
147+ using ( FileStream fileStream = File . OpenRead ( filePath ) )
148+ return Convert . ToBase64String ( SHA256 . ComputeHash ( fileStream ) ) ;
177149 }
178150
179151 public static string GenerateKey ( int size = 1000 )
180152 {
181- Random r = new Random ( ) ;
182153 string output = "" ;
183154
184155 for ( int i = 0 ; i < size ; ++ i )
185156 {
186- int [ ] rs = { r . Next ( '0' , '9' + 1 ) , r . Next ( 'a' , 'z' + 1 ) , r . Next ( 'A' , 'Z' + 1 ) } ;
187- output += ( char ) rs [ r . Next ( 3 ) ] ;
157+ int [ ] rs = { _random . Next ( '0' , '9' + 1 ) , _random . Next ( 'a' , 'z' + 1 ) , _random . Next ( 'A' , 'Z' + 1 ) } ;
158+ output += ( char ) rs [ _random . Next ( 3 ) ] ;
188159 }
189160
190161 return output . ToUpper ( ) ;
@@ -316,9 +287,9 @@ public static DateTime GetNetworkTime()
316287 private static uint SwapEndianness ( ulong x )
317288 {
318289 return ( uint ) ( ( ( x & 0x000000ff ) << 24 ) +
319- ( ( x & 0x0000ff00 ) << 8 ) +
320- ( ( x & 0x00ff0000 ) >> 8 ) +
321- ( ( x & 0xff000000 ) >> 24 ) ) ;
290+ ( ( x & 0x0000ff00 ) << 8 ) +
291+ ( ( x & 0x00ff0000 ) >> 8 ) +
292+ ( ( x & 0xff000000 ) >> 24 ) ) ;
322293 }
323294 }
324295
@@ -406,10 +377,11 @@ public override string ToString()
406377 footer += String . IsNullOrEmpty ( this . Footer . IconURL ) ? "}" : ( $ ",\" icon_url:" + "\" " + this . Footer . IconURL + "\" }" ) ;
407378 }
408379
409- string field = this . Fields == null ? "" : $ "\" fields\" :[";
380+ string field = this . Fields == null ? "" : $ "\" fields\" :[";
410381 this . Fields . ForEach ( item => field += "{" + $ "\" name\" : \" { item . Name } \" ," +
411382 $ "\" value\" : \" { item . Value } \" ," +
412383 $ "\" inline\" : { ( item . Inline ? "true" : "false" ) } " + "}," ) ;
384+
413385 field = ( field [ field . Length - 1 ] == ',' ? field . Remove ( field . Length - 1 , 1 ) : "" ) + "]" ;
414386 field = field == "\" fields\" :[]" ? "" : field ;
415387 field += ( field != "" && footer != "\" footer\" :[]" ) ? "," : "" ;
@@ -425,7 +397,6 @@ public override string ToString()
425397 "\" embed\" :{" +
426398 $ "\" description\" :\" { this . Description } \" ," +
427399 $ "{ title } " +
428- //$"\"title\":\"{this.Title}\"" +
429400 $ "{ color } " +
430401 $ "{ time } " +
431402 $ "{ field } " +
@@ -703,7 +674,7 @@ private static string identifier
703674 private static string identifier ( string wmiClass , string wmiProperty )
704675 {
705676 string result = "" ;
706- ManagementClass mc = new System . Management . ManagementClass ( wmiClass ) ;
677+ ManagementClass mc = new ManagementClass ( wmiClass ) ;
707678 ManagementObjectCollection moc = mc . GetInstances ( ) ;
708679 foreach ( ManagementObject mo in moc )
709680 {
@@ -720,46 +691,7 @@ private static string identifier(string wmiClass, string wmiProperty)
720691 }
721692 return result ;
722693 }
723- private static string CpuId ( )
724- {
725- //Uses first CPU identifier available in order of preference
726- //Don't get all identifiers, as it is very time consuming
727-
728- string retVal = /*identifier("Win32_Processor", "UniqueId")*/ "" ;
729- if ( retVal == "" ) //If no UniqueID, use ProcessorID
730- {
731- retVal = identifier ( "Win32_Processor" , "ProcessorId" ) ;
732- if ( retVal == "" ) //If no ProcessorId, use Name
733- {
734- retVal = identifier ( "Win32_Processor" , "Name" ) ;
735- if ( retVal == "" ) //If no Name, use Manufacturer
736- {
737- retVal = identifier ( "Win32_Processor" , "Manufacturer" ) ;
738- }
739- //Add clock speed for extra security
740- retVal += identifier ( "Win32_Processor" , "MaxClockSpeed" ) ;
741- }
742- }
743- return retVal ;
744- }
745- //BIOS Identifier
746- private static string BiosId ( )
747- {
748- return identifier ( "Win32_BIOS" , "Manufacturer" )
749- + identifier ( "Win32_BIOS" , "SMBIOSBIOSVersion" )
750- + identifier ( "Win32_BIOS" , "IdentificationCode" )
751- + identifier ( "Win32_BIOS" , "SerialNumber" )
752- + identifier ( "Win32_BIOS" , "ReleaseDate" )
753- + identifier ( "Win32_BIOS" , "Version" ) ;
754- }
755- //Main physical hard drive ID
756- private static string DiskId ( )
757- {
758- return identifier ( "Win32_DiskDrive" , "Model" )
759- + identifier ( "Win32_DiskDrive" , "Manufacturer" )
760- + identifier ( "Win32_DiskDrive" , "Signature" )
761- + identifier ( "Win32_DiskDrive" , "TotalHeads" ) ;
762- }
694+
763695 //Motherboard ID
764696 private static string BaseId ( )
765697 {
0 commit comments