@@ -43,7 +43,7 @@ private static string GetRandomStr(int length)
4343 StringBuilder num = new StringBuilder ( ) ;
4444
4545 Random rnd = new Random ( DateTime . Now . Millisecond ) ;
46- for ( int i = 0 ; i < length ; i ++ )
46+ for ( int i = 0 ; i < length ; i ++ )
4747 {
4848 num . Append ( arrChar [ rnd . Next ( 0 , arrChar . Length ) ] . ToString ( ) ) ;
4949 }
@@ -258,10 +258,10 @@ public static string RSAEncrypt(string publicKey, string srcString)
258258 Check . Argument . IsNotEmpty ( publicKey , nameof ( publicKey ) ) ;
259259 Check . Argument . IsNotEmpty ( srcString , nameof ( srcString ) ) ;
260260
261- using ( RSA rsa = RSA . Create ( ) )
261+ using ( RSA rsa = RSA . Create ( 2048 ) )
262262 {
263263 rsa . FromJsonString ( publicKey ) ;
264- byte [ ] encryptBytes = rsa . Encrypt ( Encoding . UTF8 . GetBytes ( srcString ) , RSAEncryptionPadding . OaepSHA1 ) ;
264+ byte [ ] encryptBytes = rsa . Encrypt ( Encoding . UTF8 . GetBytes ( srcString ) , RSAEncryptionPadding . OaepSHA512 ) ;
265265 return encryptBytes . ToHexString ( ) ;
266266 }
267267 }
@@ -276,22 +276,38 @@ public static string RSADecrypt(string privateKey, string srcString)
276276 Check . Argument . IsNotEmpty ( privateKey , nameof ( privateKey ) ) ;
277277 Check . Argument . IsNotEmpty ( srcString , nameof ( srcString ) ) ;
278278
279- using ( RSA rsa = RSA . Create ( ) )
279+ using ( RSA rsa = RSA . Create ( 2048 ) )
280280 {
281281 rsa . FromJsonString ( privateKey ) ;
282282 byte [ ] srcBytes = srcString . ToBytes ( ) ;
283- byte [ ] decryptBytes = rsa . Decrypt ( srcBytes , RSAEncryptionPadding . OaepSHA1 ) ;
283+ byte [ ] decryptBytes = rsa . Decrypt ( srcBytes , RSAEncryptionPadding . OaepSHA512 ) ;
284284 return Encoding . UTF8 . GetString ( decryptBytes ) ;
285285 }
286286 }
287+
288+ /// <summary>
289+ /// RSA Instance
290+ /// </summary>
291+ /// <param name="rsaKey"></param>
292+ /// <returns></returns>
293+ public static RSA RSAInstance ( string rsaKey )
294+ {
295+ Check . Argument . IsNotEmpty ( rsaKey , nameof ( rsaKey ) ) ;
296+ RSA rsa = RSA . Create ( ) ;
297+
298+ rsa . FromJsonString ( rsaKey ) ;
299+ return rsa ;
300+ }
301+
287302 /// <summary>
288303 /// Create an RSA key
289304 /// </summary>
290305 /// <returns></returns>
291306 public static RSAKey CreateRsaKey ( )
292307 {
293- using ( RSA rsa = RSA . Create ( ) )
308+ using ( RSA rsa = RSA . Create ( 2048 ) )
294309 {
310+
295311 string publicKey = rsa . ToJsonString ( false ) ;
296312 string privateKey = rsa . ToJsonString ( true ) ;
297313
@@ -609,7 +625,7 @@ private static string CreateMachineKey(int length)
609625 rng . GetBytes ( random ) ;
610626
611627 StringBuilder machineKey = new StringBuilder ( length ) ;
612- for ( int i = 0 ; i < random . Length ; i ++ )
628+ for ( int i = 0 ; i < random . Length ; i ++ )
613629 {
614630 machineKey . Append ( string . Format ( "{0:X2}" , random [ i ] ) ) ;
615631 }
0 commit comments