Skip to content

Commit 7cbe76c

Browse files
committed
update readme and test
1 parent 942981b commit 7cbe76c

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,24 @@ Install-Package NETCore.Encrypt -Version 2.0.0
5353
```
5454

5555
## RSA
56+
57+
- #### Enum RsaSzie
58+
59+
```csharp
60+
public enum RsaSize
61+
{
62+
R2048=2048,
63+
R3072=3072,
64+
R4096=4096
65+
}
66+
```
5667

57-
- #### Create RSA Key
68+
- #### Create RSA Key with RsaSize(update at version 2.0.1)
5869

5970
```csharp
60-
var rsaKey = EncryptProvider.CreateRsaKey();
71+
var rsaKey = EncryptProvider.CreateRsaKey(); //default is 2048
72+
73+
// var rsaKey = EncryptProvider.CreateRsaKey(RsaSize.R3072);
6174
6275
var publicKey = rsaKey.PublicKey;
6376
var privateKey = rsaKey.PrivateKey;
@@ -81,6 +94,13 @@ Install-Package NETCore.Encrypt -Version 2.0.0
8194

8295
var decrypted = EncryptProvider.RSADecrypt(privateKey, encryptedStr);
8396
```
97+
98+
- #### RSA from string (add at version 2.0.1)
99+
100+
```csharp
101+
var privateKey = rsaKey.PrivateKey;
102+
RSA rsa = EncryptProvider.RSAFromString(privateKey);
103+
```
84104

85105
## MD5
86106

src/NETCore.Encrypt/Internal/RsaSize.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace NETCore.Encrypt
66
{
77
public enum RsaSize
88
{
9-
R1024=1024,
109
R2048=2048,
1110
R3072=3072,
1211
R4096=4096

test/NETCore.Encrypt.Tests/RSA_Tests.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ namespace NETCore.Encrypt.Tests
99
public class RSA_Tests
1010
{
1111

12-
[Fact(DisplayName = "Create rsa key test")]
13-
public void Create_RSAKey_Test()
12+
[Theory]
13+
[InlineData(RsaSize.R2048)]
14+
[InlineData(RsaSize.R3072)]
15+
[InlineData(RsaSize.R4096)]
16+
public void Create_RSAKey_Test(RsaSize size)
1417
{
1518
//Act
16-
var rsaKey = EncryptProvider.CreateRsaKey();
19+
var rsaKey = EncryptProvider.CreateRsaKey(size);
1720

1821
//Assert
1922
Assert.NotNull(rsaKey);
@@ -23,10 +26,14 @@ public void Create_RSAKey_Test()
2326
Assert.NotEmpty(rsaKey.Modulus);
2427
}
2528

26-
[Fact(DisplayName = "Rsa encrypt success")]
27-
public void Rsa_Encrypt_Success_Test()
29+
[Theory]
30+
31+
[InlineData(RsaSize.R2048)]
32+
[InlineData(RsaSize.R3072)]
33+
[InlineData(RsaSize.R4096)]
34+
public void Rsa_Encrypt_Success_Test(RsaSize size)
2835
{
29-
var rsaKey = EncryptProvider.CreateRsaKey();
36+
var rsaKey = EncryptProvider.CreateRsaKey(size);
3037
var srcString = "rsa encrypt";
3138

3239
//Act
@@ -56,10 +63,13 @@ public void Rsa_Encrypt_EmptyData_Test()
5663
Assert.Throws<ArgumentException>(() => EncryptProvider.RSAEncrypt(rsaKey.PublicKey, srcString));
5764
}
5865

59-
[Fact(DisplayName = "Rsa decrypt success")]
60-
public void Rsa_Decrypt_Success_Test()
66+
[Theory]
67+
[InlineData(RsaSize.R2048)]
68+
[InlineData(RsaSize.R3072)]
69+
[InlineData(RsaSize.R4096)]
70+
public void Rsa_Decrypt_Success_Test(RsaSize size)
6171
{
62-
var rsaKey = EncryptProvider.CreateRsaKey();
72+
var rsaKey = EncryptProvider.CreateRsaKey(size);
6373
var srcString = "rsa decrypt";
6474

6575
//Act

0 commit comments

Comments
 (0)