Skip to content

Commit 4cd9990

Browse files
committed
Merge branch 'master' into dev_raphael_aes
2 parents 3f8bb82 + 71a61f5 commit 4cd9990

2 files changed

Lines changed: 78 additions & 42 deletions

File tree

src/SafeCrypt.Lib/README.md

Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,46 +34,92 @@ To use the SafeCrypt library in your C# project, follow these steps:
3434

3535
Now, you can reference the SafeCrypt library in your C# project.
3636

37-
## Usage
37+
## Basic Usage
3838

39-
To use the library in your C# application, instantiate the `SafeCrypt` class and call the provided methods. Here's a simple example:
39+
To use the library in your C# application, instantiate the `AesEncryption` or `AesDecryption` class and call the provided methods. Here's a simple example:
4040

4141
```csharp
42-
using SafeCrypt;
42+
using SafeCrypt.AESDecryption;
43+
using SafeCrypt.AESEncryption;
44+
using SafeCrypt.Models;
4345

4446
class Program
4547
{
46-
static void Main()
48+
static void Main()
4749
{
4850
var aesEncryptor = new AesEncryption();
49-
var encryptedData = aesEncryptor.AesEncrypt("Hello, World!", "mySecretKey");
50-
Console.WriteLine($"Encrypted Data: {encryptedData.Data}");
51+
52+
var encryptedData = aesEncryptor.EncryptToBase64String("Hello, World!", "gdjdtsraewsuteastwerse=="
53+
54+
Console.WriteLine($"Encrypted Data: {encryptedData.EncryptedData}");
5155
Console.WriteLine($"Initialization Vector: {encryptedData.Iv}");
56+
57+
var aesDecryptor = new AesDecryption();
58+
59+
var parameterToDecrypt = new DecryptionParameters
60+
{
61+
DataToDecrypt = encryptedData.EncryptedData,
62+
SecretKey = encryptedData.SecretKey,
63+
IV = encryptedData.IV
64+
65+
};
66+
67+
var data = aesDecryptor.DecryptFromBase64String(parameterToDecrypt)
68+
69+
Console.WriteLine($"Decrypted Data: {data.DecryptedData}");
70+
Console.WriteLine($"Initialization Vector: {data.Iv}");
5271
}
5372
}
54-
```
5573

56-
## API Reference
5774

58-
### `AesEncryption`
75+
-------------------------------------------------------------------------------------------------------
5976

60-
- `AesEncrypt(byte[] data, byte[] secretKey, byte[] iv): byte[]`
61-
- Encrypts a byte array using AES algorithm.
62-
- Parameters:
63-
- `data`: The data to encrypt.
64-
- `secretKey`: The secret key for encryption.
65-
- `iv`: The initialization vector for encryption.
66-
- Returns: The encrypted data.
77+
using SafeCrypt.AESDecryption;
78+
using SafeCrypt.AESEncryption;
79+
using SafeCrypt.Models;
6780

68-
## Examples
81+
class Program
82+
{
83+
static void Main()
84+
{
85+
var dataToEncrypt = "Data to Encrypt";
6986

70-
### Encrypting a String
87+
var iv = "gyrthusdgythisdg";
88+
var secret = "hghjuytsdfraestwsgtere==";
7189

72-
```csharp
73-
var aesEncryptor = new AesEncryption();
74-
var encryptionData = aesEncryptor.AesEncrypt("Hello, World!", "mySecretKey");
75-
Console.WriteLine($"Encrypted Data: {encryptionData.Data}");
76-
Console.WriteLine($"Initialization Vector: {encryptionData.Iv}");
90+
var encryptionParam = new EncryptionParameters
91+
{
92+
DataToEncrypt = dataToEncrypt,
93+
IV = iv,
94+
SecretKey = secret
95+
};
96+
97+
var encryptor = new AesEncryption();
98+
99+
var response = encryptor.EncryptToBase64String(encryptionParam.DataToEncrypt, secret);
100+
101+
Console.WriteLine(response.EncryptedData);
102+
Console.WriteLine(response.Iv);
103+
Console.WriteLine(response.SecretKey);
104+
105+
106+
107+
var decryptorParam = new DecryptionParameters
108+
{
109+
IV = response.Iv,
110+
SecretKey = secret,
111+
DataToDecrypt = response.EncryptedData
112+
};
113+
114+
115+
var decryptor = new AesDecryption();
116+
var decryptionData = decryptor.DecryptFromBase64String(decryptorParam);
117+
118+
Console.WriteLine(decryptionData.DecryptedData);
119+
Console.WriteLine(decryptionData.Iv);
120+
Console.WriteLine(decryptionData.SecretKey);
121+
}
122+
}
77123
```
78124

79125
## Contributing

src/SafeCrypt.Lib/SafeCrypt.csproj

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,27 @@
1515
<PackageReadmeFile>README.md</PackageReadmeFile>
1616
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
1717
<PackageLicenseFile>MitLicense.txt</PackageLicenseFile>
18-
<PackageReleaseNotes>SafeCrypt Library - Release Notes
18+
<PackageReleaseNotes>SafeCrypt Library - Release Notes - Version 1.0.1
1919

20-
Version 1.0.0
20+
This release (version 1.0.1) includes updates to the documentation and namespace changes. We have improved the README document to provide more comprehensive information about the library and made adjustments to the namespaces for better organization.
2121

22-
Highlights:
23-
- New Features:
24-
- `EncryptToHexString`: Easily encrypt data with a hexadecimal string output.
25-
- `DecryptFromBase64String`: Decrypt Base64-encoded string data with validation.
26-
- `GenerateAesKey`: Generate a random AES key of a specified size.
22+
Changes
2723

28-
- Improvements:
29-
- Enhanced validation checks for input parameters in encryption and decryption methods.
30-
- Improved error handling for decryption, including padding errors.
24+
- Updated README document with detailed usage instructions, API references, and contribution guidelines.
25+
- Made changes to namespaces for better organization and clarity in the codebase.
3126

32-
- Bug Fixes:
33-
- Resolved issues related to padding errors during decryption.
27+
Bug Fixes
3428

35-
- Documentation:
36-
- Updated and expanded the README file for better understanding and usage instructions.
37-
- Added XML documentation comments to improve code documentation.
38-
39-
- Security:
40-
- Improved key validation to ensure secure encryption and decryption.
29+
No bug fixes in this release.
4130

4231
Upgrade Command:
43-
dotnet add package SafeCrypt --version 1.0.0
32+
dotnet add package SafeCrypt --version 1.0.1
4433

4534
Feedback and Contributions:
4635
We appreciate your feedback and contributions! If you encounter any issues or have suggestions, please create an issue on GitHub: https://github.com/selfmadecode/SafeCrypt/issues
4736

4837
Thank you for using the SafeCrypt Library!</PackageReleaseNotes>
38+
<Version>1.0.1</Version>
4939
</PropertyGroup>
5040

5141
<ItemGroup>

0 commit comments

Comments
 (0)