7
7
using System . Net ;
8
8
using System . Net . Http ;
9
9
using System . Net . Sockets ;
10
+ using System . Numerics ;
11
+ using System . Security . Cryptography ;
10
12
using System . Text ;
11
13
using System . Threading . Tasks ;
12
14
using System . Web . Script . Serialization ;
@@ -333,9 +335,10 @@ public static List<AddSoftware> CheckForUpdate(List<AddSoftware> lSoftware, stri
333
335
if ( lSoftware . Count > 0 )
334
336
{
335
337
JavaScriptSerializer ser = new JavaScriptSerializer ( ) ;
336
- HttpContent oCont = new StringContent ( ser . Serialize ( lSoftware ) , Encoding . UTF8 , "application/json" ) ;
337
-
338
- var response = oClient . PostAsync ( sURL + "/rest/v2/checkforupdate" , oCont ) ;
338
+ string sSoftware = ser . Serialize ( lSoftware ) ;
339
+ HttpContent oCont = new StringContent ( sSoftware , Encoding . UTF8 , "application/json" ) ;
340
+ string sHash = CalculateMD5HashString ( sSoftware ) ;
341
+ var response = oClient . PostAsync ( sURL + $ "/rest/v2/checkforupdate/{ sHash } ", oCont ) ;
339
342
response . Wait ( 120000 ) ; //2min max
340
343
if ( response . IsCompleted )
341
344
{
@@ -353,6 +356,56 @@ public static List<AddSoftware> CheckForUpdate(List<AddSoftware> lSoftware, stri
353
356
return new List < AddSoftware > ( ) ;
354
357
}
355
358
359
+ #region Hash
360
+ private const string Digits = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" ;
361
+
362
+ private static byte [ ] CalculateMD5Hash ( string input )
363
+ {
364
+ MD5 md5 = System . Security . Cryptography . MD5 . Create ( ) ;
365
+ byte [ ] inputBytes = System . Text . Encoding . ASCII . GetBytes ( input ) ;
366
+ byte [ ] hash = md5 . ComputeHash ( inputBytes ) ;
367
+ byte [ ] mhash = new byte [ hash . Length + 2 ] ;
368
+ hash . CopyTo ( mhash , 2 ) ;
369
+ //Add Multihash identifier
370
+ mhash [ 0 ] = 0xD5 ; //MD5
371
+ mhash [ 1 ] = Convert . ToByte ( hash . Length ) ; //Hash legth
372
+ return mhash ;
373
+ }
374
+
375
+ private static string Encode58 ( byte [ ] data )
376
+ {
377
+ // Decode byte[] to BigInteger
378
+ BigInteger intData = 0 ;
379
+ for ( int i = 0 ; i < data . Length ; i ++ )
380
+ {
381
+ intData = intData * 256 + data [ i ] ;
382
+ }
383
+
384
+ // Encode BigInteger to Base58 string
385
+ string result = "" ;
386
+ while ( intData > 0 )
387
+ {
388
+ int remainder = ( int ) ( intData % 58 ) ;
389
+ intData /= 58 ;
390
+ result = Digits [ remainder ] + result ;
391
+ }
392
+
393
+ // Append `1` for each leading 0 byte
394
+ for ( int i = 0 ; i < data . Length && data [ i ] == 0 ; i ++ )
395
+ {
396
+ result = '1' + result ;
397
+ }
398
+
399
+ return result ;
400
+ }
401
+
402
+ public static string CalculateMD5HashString ( string input )
403
+ {
404
+ return Encode58 ( CalculateMD5Hash ( input ) ) ;
405
+ }
406
+
407
+ #endregion
408
+
356
409
}
357
410
358
411
public class GetSoftware
0 commit comments