1
- using System ;
2
- using System . Security . Cryptography ;
1
+ using System . Security . Cryptography ;
2
+ using System . Text ;
3
3
using com . tvd12 . ezyfoxserver . client . builder ;
4
4
5
5
namespace com . tvd12 . ezyfoxserver . client . security
6
6
{
7
- public class EzyAsyCrypt
8
- {
7
+ public class EzyAsyCrypt
8
+ {
9
9
private readonly byte [ ] privateKey ;
10
10
11
11
protected EzyAsyCrypt ( Builder builder )
@@ -15,32 +15,13 @@ protected EzyAsyCrypt(Builder builder)
15
15
16
16
public byte [ ] decrypt ( byte [ ] message )
17
17
{
18
- using ( var rsa = RSA . Create ( ) )
18
+ using ( var rsa = new RSACryptoServiceProvider ( ) )
19
19
{
20
- rsa . ImportParameters ( convertToPrivateKeyParameters ( ) ) ;
21
- return rsa . Decrypt ( message , RSAEncryptionPadding . Pkcs1 ) ;
20
+ rsa . FromXmlString ( Encoding . UTF8 . GetString ( privateKey ) ) ;
21
+ return rsa . Decrypt ( message , false ) ;
22
22
}
23
23
}
24
24
25
- private RSAParameters convertToPrivateKeyParameters ( )
26
- {
27
- RSAParameters privateKeyParameters = new RSAParameters ( ) ;
28
- using ( var rsa = RSA . Create ( ) )
29
- {
30
- rsa . ImportPkcs8PrivateKey ( privateKey , out _ ) ;
31
- privateKeyParameters . Modulus = rsa . ExportParameters ( true ) . Modulus ;
32
- privateKeyParameters . Exponent = rsa . ExportParameters ( true ) . Exponent ;
33
- privateKeyParameters . D = rsa . ExportParameters ( true ) . D ;
34
- privateKeyParameters . P = rsa . ExportParameters ( true ) . P ;
35
- privateKeyParameters . Q = rsa . ExportParameters ( true ) . Q ;
36
- privateKeyParameters . DP = rsa . ExportParameters ( true ) . DP ;
37
- privateKeyParameters . DQ = rsa . ExportParameters ( true ) . DQ ;
38
- privateKeyParameters . InverseQ = rsa . ExportParameters ( true ) . InverseQ ;
39
- }
40
-
41
- return privateKeyParameters ;
42
- }
43
-
44
25
public static Builder builder ( )
45
26
{
46
27
return new Builder ( ) ;
@@ -63,4 +44,3 @@ public EzyAsyCrypt build()
63
44
}
64
45
}
65
46
}
66
-
0 commit comments