@@ -30,7 +30,7 @@ private static string GetRandomStr(int length)
30
30
StringBuilder num = new StringBuilder ( ) ;
31
31
32
32
Random rnd = new Random ( DateTime . Now . Millisecond ) ;
33
- for ( int i = 0 ; i < length ; i ++ )
33
+ for ( int i = 0 ; i < length ; i ++ )
34
34
{
35
35
num . Append ( arrChar [ rnd . Next ( 0 , arrChar . Length ) ] . ToString ( ) ) ;
36
36
}
@@ -235,7 +235,7 @@ public static string AESDecrypt(string data, string key)
235
235
{
236
236
try
237
237
{
238
- byte [ ] tmp = new byte [ encryptedBytes . Length ] ;
238
+ byte [ ] tmp = new byte [ encryptedBytes . Length ] ;
239
239
int len = cryptoStream . Read ( tmp , 0 , encryptedBytes . Length ) ;
240
240
byte [ ] ret = new byte [ len ] ;
241
241
Array . Copy ( tmp , 0 , ret , 0 , len ) ;
@@ -361,7 +361,7 @@ public static string RSAEncrypt(string publicKey, string srcString)
361
361
using ( RSA rsa = RSA . Create ( ) )
362
362
{
363
363
rsa . FromJsonString ( publicKey ) ;
364
- byte [ ] encryptBytes = rsa . Encrypt ( Encoding . UTF8 . GetBytes ( srcString ) , RSAEncryptionPadding . OaepSHA512 ) ;
364
+ byte [ ] encryptBytes = rsa . Encrypt ( Encoding . UTF8 . GetBytes ( srcString ) , RSAEncryptionPadding . Pkcs1 ) ;
365
365
return encryptBytes . ToHexString ( ) ;
366
366
}
367
367
}
@@ -380,7 +380,7 @@ public static string RSADecrypt(string privateKey, string srcString)
380
380
{
381
381
rsa . FromJsonString ( privateKey ) ;
382
382
byte [ ] srcBytes = srcString . ToBytes ( ) ;
383
- byte [ ] decryptBytes = rsa . Decrypt ( srcBytes , RSAEncryptionPadding . OaepSHA512 ) ;
383
+ byte [ ] decryptBytes = rsa . Decrypt ( srcBytes , RSAEncryptionPadding . Pkcs1 ) ;
384
384
return Encoding . UTF8 . GetString ( decryptBytes ) ;
385
385
}
386
386
}
@@ -406,8 +406,10 @@ public static RSA RSAFromString(string rsaKey)
406
406
/// <returns></returns>
407
407
public static RSAKey CreateRsaKey ( RsaSize rsaSize = RsaSize . R2048 )
408
408
{
409
- using ( RSA rsa = RSA . Create ( ( int ) rsaSize ) )
409
+ using ( RSA rsa = RSA . Create ( ) )
410
410
{
411
+ rsa . KeySize = ( int ) RsaSize . R2048 ;
412
+
411
413
string publicKey = rsa . ToJsonString ( false ) ;
412
414
string privateKey = rsa . ToJsonString ( true ) ;
413
415
@@ -440,13 +442,13 @@ public static string Md5(string srcString, MD5Length length = MD5Length.L32)
440
442
byte [ ] bytes_md5_out = md5 . ComputeHash ( bytes_md5_in ) ;
441
443
442
444
str_md5_out = length == MD5Length . L32
443
- ? BitConverter . ToString ( bytes_md5_out )
445
+ ? BitConverter . ToString ( bytes_md5_out )
444
446
: BitConverter . ToString ( bytes_md5_out , 4 , 8 ) ;
445
-
447
+
446
448
str_md5_out = str_md5_out . Replace ( "-" , "" ) ;
447
449
return str_md5_out ;
448
450
}
449
- }
451
+ }
450
452
#endregion
451
453
452
454
#region HMACMD5
@@ -730,7 +732,7 @@ private static string CreateMachineKey(int length)
730
732
rng . GetBytes ( random ) ;
731
733
732
734
StringBuilder machineKey = new StringBuilder ( length ) ;
733
- for ( int i = 0 ; i < random . Length ; i ++ )
735
+ for ( int i = 0 ; i < random . Length ; i ++ )
734
736
{
735
737
machineKey . Append ( string . Format ( "{0:X2}" , random [ i ] ) ) ;
736
738
}
0 commit comments