From a53a9046304de6375fc6045ff7b731d2bc8c5546 Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Fri, 2 Feb 2024 11:43:52 +0100 Subject: [PATCH 01/27] feat: update release note in csproj --- src/SafeCrypt.Lib/SafeCrypt.csproj | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/SafeCrypt.Lib/SafeCrypt.csproj b/src/SafeCrypt.Lib/SafeCrypt.csproj index cf1749e..2368bc6 100644 --- a/src/SafeCrypt.Lib/SafeCrypt.csproj +++ b/src/SafeCrypt.Lib/SafeCrypt.csproj @@ -15,27 +15,26 @@ README.md True MitLicense.txt - SafeCrypt Library - Release Notes - Version 1.0.1 + SafeCrypt Library - Release Notes - Version 1.0.2 -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. +We are excited to announce the latest version of SafeCrypt (v1.0.2), featuring a significant enhancement to our encryption methods. In this release, all encryption operations are now asynchronous, providing improved performance and responsiveness. -Changes - -- Updated README document with detailed usage instructions, API references, and contribution guidelines. -- Made changes to namespaces for better organization and clarity in the codebase. +What's New: +Async Encryption and Decryption: +We have made all encryption methods asynchronous to better align with modern programming practices and enhance the overall responsiveness of SafeCrypt. Bug Fixes No bug fixes in this release. Upgrade Command: -dotnet add package SafeCrypt --version 1.0.1 +dotnet add package SafeCrypt --version 1.0.2 Feedback and Contributions: 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 Thank you for using the SafeCrypt Library! - 1.0.1 + 1.0.2 From 4b028498b34be04677a5cb6092ae5c5286470933 Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Tue, 6 Feb 2024 14:44:57 +0100 Subject: [PATCH 02/27] feat: add RsaEncryptionParameters to hold parameters for encryption --- .../Models/Encrypt/RsaEncryptionParameters.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/Encrypt/RsaEncryptionParameters.cs diff --git a/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/Encrypt/RsaEncryptionParameters.cs b/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/Encrypt/RsaEncryptionParameters.cs new file mode 100644 index 0000000..ee9d4b8 --- /dev/null +++ b/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/Encrypt/RsaEncryptionParameters.cs @@ -0,0 +1,20 @@ +namespace SafeCrypt.RsaEncryption.Models +{ + internal class RsaEncryptionParameters : IEncryptionData + { + /// + /// Gets or sets the public key for RSA encryption. + /// + public string PublicKey { get; set; } + + /// + /// Gets or sets the private key for RSA encryption. + /// + public string PrivateKey { get; set; } + + /// + /// Gets or sets the data to be encrypted using RSA. + /// + public string DataToEncrypt { get; set; } + } +} From c10203ae290a431b6cdefea2431248c914c2ad41 Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Tue, 6 Feb 2024 14:45:29 +0100 Subject: [PATCH 03/27] feat: add RsaEncryptionResult --- .../Models/RsaEncryptionResult.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/RsaEncryptionResult.cs diff --git a/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/RsaEncryptionResult.cs b/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/RsaEncryptionResult.cs new file mode 100644 index 0000000..87d6430 --- /dev/null +++ b/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/RsaEncryptionResult.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SafeCrypt.RsaEncryption.Models +{ + public class RsaEncryptionResult + { + /// + /// Gets or sets the encrypted data. + /// + public byte[] EncryptedData { get; set; } + + /// + /// Gets or sets the list of errors encountered during encryption. + /// + public List Errors { get; set; } + + /// + /// Gets or sets the public key used for encryption. + /// + public string PublicKey { get; set; } + + /// + /// Gets or sets the private key used for encryption. + /// + public string PrivateKey { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public RsaEncryptionResult() + { + Errors = new List(); + } + } +} From ea3b02ccc75eeb7e1620a97ec7125b491a8b8198 Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Tue, 6 Feb 2024 14:47:30 +0100 Subject: [PATCH 04/27] feat: add IEncryptionData interface to hold related properties --- src/SafeCrypt.Lib/Interface/IEncryptionData.cs | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/SafeCrypt.Lib/Interface/IEncryptionData.cs diff --git a/src/SafeCrypt.Lib/Interface/IEncryptionData.cs b/src/SafeCrypt.Lib/Interface/IEncryptionData.cs new file mode 100644 index 0000000..b0418df --- /dev/null +++ b/src/SafeCrypt.Lib/Interface/IEncryptionData.cs @@ -0,0 +1,7 @@ +namespace SafeCrypt +{ + internal interface IEncryptionData + { + string DataToEncrypt { get; set; } + } +} From b258e2c4e8f8b8e6ca9505446d877c238ac664a9 Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Tue, 6 Feb 2024 14:49:12 +0100 Subject: [PATCH 05/27] feat: add base Rsa encryption class with method for data encryption and decryption including method to generate keys --- .../Encryption/RsaEncryption/RsaEncryption.cs | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs diff --git a/src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs b/src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs new file mode 100644 index 0000000..e50de3d --- /dev/null +++ b/src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs @@ -0,0 +1,65 @@ +using System.Security.Cryptography; +using System.Text; +using System; +using System.Threading.Tasks; + +namespace SafeCrypt.RsaEncryption +{ + public class RsaEncryption + { + /// + /// Generates RSA key pair. + /// + /// The size of the key pair (e.g., 1024, 2048 bits). + /// The generated RSA key pair. + public static Tuple GenerateRsaKeys(int keySize) + { + using (var rsa = new RSACryptoServiceProvider(keySize)) + { + string publicKey = rsa.ToXmlString(false); // Don't include private key + string privateKey = rsa.ToXmlString(true); // Include private key + + return new Tuple(publicKey, privateKey); + } + } + + /// + /// Encrypts data using RSA public key. + /// + /// The data to be encrypted. + /// The RSA public key. + /// The encrypted data. + public static async Task EncryptAsync(string data, string publicKey) + { + + return await Task.Run(() => { + using (var rsa = new RSACryptoServiceProvider()) + { + rsa.FromXmlString(publicKey); + byte[] dataBytes = Encoding.UTF8.GetBytes(data); + byte[] encryptedData = rsa.Encrypt(dataBytes, false); + return encryptedData; + } + }); + } + + /// + /// Decrypts data using RSA private key. + /// + /// The encrypted data. + /// The RSA private key. + /// The decrypted data. + public static async Task DecryptAsync(byte[] encryptedData, string privateKey) + { + return await Task.Run(() => + { + using (var rsa = new RSACryptoServiceProvider()) + { + rsa.FromXmlString(privateKey); + byte[] decryptedData = rsa.Decrypt(encryptedData, false); + return Encoding.UTF8.GetString(decryptedData); + } + }); + } + } +} From 6a932efb1b85a03a2cb586befb6f4e63e16144de Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Tue, 6 Feb 2024 15:12:05 +0100 Subject: [PATCH 06/27] feat: comment out Public key from RsaEncryptionResult --- .../RsaEncryption/Models/RsaEncryptionResult.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/RsaEncryptionResult.cs b/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/RsaEncryptionResult.cs index 87d6430..5555428 100644 --- a/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/RsaEncryptionResult.cs +++ b/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/RsaEncryptionResult.cs @@ -16,10 +16,10 @@ public class RsaEncryptionResult /// public List Errors { get; set; } - /// - /// Gets or sets the public key used for encryption. - /// - public string PublicKey { get; set; } + ///// + ///// Gets or sets the public key used for encryption. + ///// + //public string PublicKey { get; set; } /// /// Gets or sets the private key used for encryption. From bc1b5463ccbcc51735cc25786c6852d7fb94c45e Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Tue, 6 Feb 2024 15:13:20 +0100 Subject: [PATCH 07/27] feat: use try catch for encryption --- .../Encryption/RsaEncryption/RsaEncryption.cs | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs b/src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs index e50de3d..5847d85 100644 --- a/src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs +++ b/src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs @@ -2,6 +2,7 @@ using System.Text; using System; using System.Threading.Tasks; +using SafeCrypt.RsaEncryption.Models; namespace SafeCrypt.RsaEncryption { @@ -29,18 +30,30 @@ public static Tuple GenerateRsaKeys(int keySize) /// The data to be encrypted. /// The RSA public key. /// The encrypted data. - public static async Task EncryptAsync(string data, string publicKey) + public static async Task EncryptAsync(string data, string publicKey) { + var result = new RsaEncryptionResult(); - return await Task.Run(() => { - using (var rsa = new RSACryptoServiceProvider()) + try + { + var encryptedData = await Task.Run(() => { - rsa.FromXmlString(publicKey); - byte[] dataBytes = Encoding.UTF8.GetBytes(data); - byte[] encryptedData = rsa.Encrypt(dataBytes, false); - return encryptedData; - } - }); + using (var rsa = new RSACryptoServiceProvider()) + { + rsa.FromXmlString(publicKey); + byte[] dataBytes = Encoding.UTF8.GetBytes(data); + return rsa.Encrypt(dataBytes, false); + } + }); + + result.EncryptedData = encryptedData; + } + catch (Exception ex) + { + result.Errors.Add(ex.Message); + } + + return result; } /// From 668f63305eb153010a2d1e8cb28bd9d4d23354c4 Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Tue, 6 Feb 2024 15:30:06 +0100 Subject: [PATCH 08/27] feat: move rsa key generation method to KeyGenerator class --- .../Encryption/RsaEncryption/RsaEncryption.cs | 18 +----------- src/SafeCrypt.Lib/Helpers/KeyGenerators.cs | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs b/src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs index 5847d85..7dd5bda 100644 --- a/src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs +++ b/src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs @@ -7,23 +7,7 @@ namespace SafeCrypt.RsaEncryption { public class RsaEncryption - { - /// - /// Generates RSA key pair. - /// - /// The size of the key pair (e.g., 1024, 2048 bits). - /// The generated RSA key pair. - public static Tuple GenerateRsaKeys(int keySize) - { - using (var rsa = new RSACryptoServiceProvider(keySize)) - { - string publicKey = rsa.ToXmlString(false); // Don't include private key - string privateKey = rsa.ToXmlString(true); // Include private key - - return new Tuple(publicKey, privateKey); - } - } - + { /// /// Encrypts data using RSA public key. /// diff --git a/src/SafeCrypt.Lib/Helpers/KeyGenerators.cs b/src/SafeCrypt.Lib/Helpers/KeyGenerators.cs index 44a2c5a..3625465 100644 --- a/src/SafeCrypt.Lib/Helpers/KeyGenerators.cs +++ b/src/SafeCrypt.Lib/Helpers/KeyGenerators.cs @@ -67,5 +67,33 @@ public static string GenerateAesSecretKey(int keySize) return Convert.ToBase64String(aesAlg.Key); } } + + /// + /// Generates a pair of RSA public and private keys with the specified key size. + /// + /// The size of the key pair (e.g., 1024, 2048 bits). + /// + /// A containing the generated RSA public and private keys. + /// Item1 represents the public key, and Item2 represents the private key. + /// + /// + /// The generated keys are in XML format. The public key does not include the private key, + /// while the private key includes both public and private components. + /// + /// The size of the key pair (e.g., 1024, 2048 bits). + /// A tuple containing the generated RSA public and private keys. + /// + /// Thrown if an error occurs during key generation. + /// + public static Tuple GenerateRsaKeys(int keySize) + { + using (var rsa = new RSACryptoServiceProvider(keySize)) + { + string publicKey = rsa.ToXmlString(false); // Don't include private key + string privateKey = rsa.ToXmlString(true); // Include private key + + return new Tuple(publicKey, privateKey); + } + } } } From f2d1d7d76a4dd8342042eeee0d261b8d05fcc7cb Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Wed, 7 Feb 2024 13:33:14 +0100 Subject: [PATCH 09/27] feat: rename algorithm class to rsa --- .../Encryption/RsaEncryption/Rsa.cs | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/SafeCrypt.Lib/Encryption/RsaEncryption/Rsa.cs diff --git a/src/SafeCrypt.Lib/Encryption/RsaEncryption/Rsa.cs b/src/SafeCrypt.Lib/Encryption/RsaEncryption/Rsa.cs new file mode 100644 index 0000000..b15d394 --- /dev/null +++ b/src/SafeCrypt.Lib/Encryption/RsaEncryption/Rsa.cs @@ -0,0 +1,80 @@ +using System; +using System.Text; +using System.Threading.Tasks; +using SafeCrypt.RsaEncryption.Models; + +namespace SafeCrypt.RsaEncryption +{ + + + public static class Rsa + { + /// + /// Asynchronously encrypts the specified data using RSA encryption. + /// + /// The parameters for RSA encryption. + /// An containing the encrypted data, and errors (if any). + public static async Task EncryptAsync(RsaEncryptionParameters model) + { + var result = new EncryptionResult(); + + if(string.IsNullOrWhiteSpace(model.DataToEncrypt)) + { + result.Errors.Add($"Data cannot be null {nameof(model.DataToEncrypt)}"); + return result; + } + + if (string.IsNullOrWhiteSpace(model.PublicKey)) + { + result.Errors.Add($"PublicKey cannot be null {nameof(model.PublicKey)}"); + return result; + } + + // asynchronously perform RSA encryption + var data = await RsaEncryption.EncryptAsync(model.DataToEncrypt, model.PublicKey); + + if(data.Errors.Count > 0) + { + // If there are errors in the encryption process, add them to the result and return + result.Errors.AddRange(data.Errors); + return result; + } + + // Convert the encrypted data to a hexadecimal string + //result.EncryptedData = BitConverter.ToString(data.EncryptedData); + result.EncryptedData = Encoding.UTF8.GetString(data.EncryptedData); //Encoding.UTF8.GetString(decryptedData) + return result; + } + + public static async Task DecryptAsync(RsaDecryptionParameters model) + { + var result = new DecryptionResult(); + + if (string.IsNullOrWhiteSpace(model.DataToDecrypt)) + { + result.Errors.Add($"Data cannot be null {nameof(model.DataToDecrypt)}"); + return result; + } + + if (string.IsNullOrWhiteSpace(model.PrivateKey)) + { + result.Errors.Add($"PrivateKey cannot be null {nameof(model.PrivateKey)}"); + return result; + } + + // asynchronously perform RSA encryption + var data = await RsaEncryption.DecryptAsync(model.DataToDecrypt, model.PrivateKey); + + if (data.Errors.Count > 0) + { + // if there are errors in the encryption process, add them to the result and return + result.Errors.AddRange(data.Errors); + return result; + } + + // convert the encrypted data to a hexadecimal string + result.DecryptedData = Encoding.UTF8.GetString(data.DecryptedData); + return result; + } + } +} From c50d51e85131ddaaa6817b041ff2041209d570f1 Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Wed, 7 Feb 2024 14:09:07 +0100 Subject: [PATCH 10/27] feat: use byte[] to hold encrypted data --- .../Models/Encrypt/RsaEncryptionParameters.cs | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/Encrypt/RsaEncryptionParameters.cs b/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/Encrypt/RsaEncryptionParameters.cs index ee9d4b8..f1c6073 100644 --- a/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/Encrypt/RsaEncryptionParameters.cs +++ b/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/Encrypt/RsaEncryptionParameters.cs @@ -1,20 +1,34 @@ -namespace SafeCrypt.RsaEncryption.Models +using System.ComponentModel.DataAnnotations; + +namespace SafeCrypt.RsaEncryption.Models { - internal class RsaEncryptionParameters : IEncryptionData + public sealed class RsaEncryptionParameters : IEncryptionData { /// /// Gets or sets the public key for RSA encryption. /// - public string PublicKey { get; set; } + [Required] + public string PublicKey { get; set; } + + /// + /// Gets or sets the data to be encrypted using RSA. + /// + [Required] + public string DataToEncrypt { get; set; } + } + public sealed class RsaDecryptionParameters + { /// - /// Gets or sets the private key for RSA encryption. + /// Gets or sets the public key for RSA encryption. /// + [Required] public string PrivateKey { get; set; } /// /// Gets or sets the data to be encrypted using RSA. /// - public string DataToEncrypt { get; set; } + [Required] + public byte[] DataToDecrypt { get; set; } } } From dcc1b7eb04dba4814c2f12a0372723c041cd513d Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Wed, 7 Feb 2024 17:51:29 +0100 Subject: [PATCH 11/27] feat: comment out byte check --- .../Encryption/RsaEncryption/Rsa.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/SafeCrypt.Lib/Encryption/RsaEncryption/Rsa.cs b/src/SafeCrypt.Lib/Encryption/RsaEncryption/Rsa.cs index b15d394..81eb84a 100644 --- a/src/SafeCrypt.Lib/Encryption/RsaEncryption/Rsa.cs +++ b/src/SafeCrypt.Lib/Encryption/RsaEncryption/Rsa.cs @@ -41,8 +41,11 @@ public static async Task EncryptAsync(RsaEncryptionParameters } // Convert the encrypted data to a hexadecimal string + //result.EncryptedData = data.EncryptedData; + //result.EncryptedData = Convert.ToBase64String(data.EncryptedData); //result.EncryptedData = BitConverter.ToString(data.EncryptedData); - result.EncryptedData = Encoding.UTF8.GetString(data.EncryptedData); //Encoding.UTF8.GetString(decryptedData) + //result.EncryptedData = Encoding.UTF8.GetString(data.EncryptedData); //Encoding.UTF8.GetString(decryptedData) + result.EncryptedData = data.EncryptedData; //Encoding.UTF8.GetString(decryptedData) return result; } @@ -50,11 +53,11 @@ public static async Task DecryptAsync(RsaDecryptionParameters { var result = new DecryptionResult(); - if (string.IsNullOrWhiteSpace(model.DataToDecrypt)) - { - result.Errors.Add($"Data cannot be null {nameof(model.DataToDecrypt)}"); - return result; - } + //if (string.IsNullOrWhiteSpace(model.DataToDecrypt)) + //{ + // result.Errors.Add($"Data cannot be null {nameof(model.DataToDecrypt)}"); + // return result; + //} if (string.IsNullOrWhiteSpace(model.PrivateKey)) { @@ -71,8 +74,7 @@ public static async Task DecryptAsync(RsaDecryptionParameters result.Errors.AddRange(data.Errors); return result; } - - // convert the encrypted data to a hexadecimal string + result.DecryptedData = Encoding.UTF8.GetString(data.DecryptedData); return result; } From 3f049005c15e3d5200dc40315f97f71c54236a98 Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Thu, 8 Feb 2024 13:03:25 +0100 Subject: [PATCH 12/27] feat: test rsa algorithms --- src/SafeCrypt.Test/Program.cs | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/SafeCrypt.Test/Program.cs b/src/SafeCrypt.Test/Program.cs index 79b733e..21cd922 100644 --- a/src/SafeCrypt.Test/Program.cs +++ b/src/SafeCrypt.Test/Program.cs @@ -2,7 +2,10 @@ using SafeCrypt.AESDecryption; using SafeCrypt.AESEncryption; +using SafeCrypt.Helpers; using SafeCrypt.Models; +using SafeCrypt.RsaEncryption; +using SafeCrypt.RsaEncryption.Models; var dataToEncrypt = "Data to Encrypt"; var secret = "hghjuytsdfraestwsgtere=="; @@ -37,4 +40,41 @@ Console.WriteLine($"Secret key: {decryptionData.SecretKey}"); + +/////////////////////////// +/// +// Example: Generate RSA keys +var rsaKeyPair = KeyGenerators.GenerateRsaKeys(2048); +string rsaPublicKey = rsaKeyPair.Item1; +string rsaPrivateKey = rsaKeyPair.Item2; + +Console.WriteLine($"pubic key {rsaPublicKey}"); +Console.WriteLine($"private key {rsaPrivateKey}"); + +// Example: Encrypt and Decrypt using RSA +string originalData = "Hello, RSA Encryption!"; + +var enModel = new RsaEncryptionParameters +{ + DataToEncrypt = originalData, + PublicKey = rsaPublicKey, +}; + +var encryptedData = await Rsa.EncryptAsync(enModel); + +var uccRYTED = new RsaDecryptionParameters +{ + DataToDecrypt = encryptedData.EncryptedData, + PrivateKey = rsaPrivateKey +}; + +var decryptedData = await Rsa.DecryptAsync(uccRYTED); + +// Display results +Console.WriteLine($"Original Data: {originalData}"); +Console.WriteLine($"Encrypted Data: {encryptedData.EncryptedData}"); +//Console.WriteLine($"Encrypted Data-------: {BitConverter.ToString(encryptedData.EncryptedData)}"); +Console.WriteLine($"Decrypted Data: {decryptedData.DecryptedData}"); + + Console.WriteLine("Hello, World!"); From c1e911e63745f546d71b9522349ee69a149f547d Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Thu, 8 Feb 2024 13:05:26 +0100 Subject: [PATCH 13/27] feat: update rsa algorithm comments --- .../Encryption/RsaEncryption/RsaEncryption.cs | 55 ++++++++++++++----- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs b/src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs index 7dd5bda..6dc57d9 100644 --- a/src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs +++ b/src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs @@ -6,15 +6,28 @@ namespace SafeCrypt.RsaEncryption { - public class RsaEncryption - { + public static class RsaEncryption + { /// - /// Encrypts data using RSA public key. + /// Asynchronously encrypts the provided data using the RSA (Rivest–Shamir–Adleman) algorithm. /// /// The data to be encrypted. - /// The RSA public key. - /// The encrypted data. - public static async Task EncryptAsync(string data, string publicKey) + /// The public key used for encryption. + /// + /// A task representing the asynchronous operation that, upon completion, + /// returns an containing the encrypted data. + /// + /// + /// This method uses the RSA algorithm to encrypt the input data with the provided public key. + /// The encryption is performed asynchronously using . + /// + /// The data to be encrypted. + /// The public key used for encryption. + /// + /// A task representing the asynchronous operation that, upon completion, + /// returns an containing the encrypted data. + /// + internal static async Task EncryptAsync(string data, string publicKey) { var result = new RsaEncryptionResult(); @@ -46,17 +59,31 @@ public static async Task EncryptAsync(string data, string p /// The encrypted data. /// The RSA private key. /// The decrypted data. - public static async Task DecryptAsync(byte[] encryptedData, string privateKey) + internal static async Task DecryptAsync(byte[] encryptedData, string privateKey) { - return await Task.Run(() => + var result = new RsaDecryptionResult(); + + try { - using (var rsa = new RSACryptoServiceProvider()) + var decryptedData = await Task.Run(() => { - rsa.FromXmlString(privateKey); - byte[] decryptedData = rsa.Decrypt(encryptedData, false); - return Encoding.UTF8.GetString(decryptedData); - } - }); + using (var rsa = new RSACryptoServiceProvider()) + { + rsa.FromXmlString(privateKey); + byte[] dataBytes = encryptedData; + return rsa.Decrypt(encryptedData, false); + } + }); + + result.DecryptedData = decryptedData; + + } + catch (Exception ex) + { + result.Errors.Add(ex.Message); + } + + return result; } } } From 2e1c45897e24e2fad01d6b1b3ca434d30a431422 Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Fri, 9 Feb 2024 21:09:54 +0100 Subject: [PATCH 14/27] faet: add rsa encryption result --- .../Models/RsaEncryptionResult.cs | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/RsaEncryptionResult.cs b/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/RsaEncryptionResult.cs index 5555428..95d21d8 100644 --- a/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/RsaEncryptionResult.cs +++ b/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/RsaEncryptionResult.cs @@ -16,6 +16,27 @@ public class RsaEncryptionResult /// public List Errors { get; set; } + /// + /// Initializes a new instance of the class. + /// + public RsaEncryptionResult() + { + Errors = new List(); + } + } + + public class RsaDecryptionResult + { + /// + /// Gets or sets the encrypted data. + /// + public byte[] DecryptedData { get; set; } + + /// + /// Gets or sets the list of errors encountered during encryption. + /// + public List Errors { get; set; } + ///// ///// Gets or sets the public key used for encryption. ///// @@ -29,7 +50,43 @@ public class RsaEncryptionResult /// /// Initializes a new instance of the class. /// - public RsaEncryptionResult() + public RsaDecryptionResult() + { + Errors = new List(); + } + } + + public class EncryptionResult + { + /// + /// Gets or sets the list of errors encountered during encryption. + /// + public List Errors { get; set; } + + /// + /// Gets or sets the encrypted data. + /// + public byte[] EncryptedData { get; set; } + + public EncryptionResult() + { + Errors = new List(); + } + } + + public class DecryptionResult + { + /// + /// Gets or sets the list of errors encountered during encryption. + /// + public List Errors { get; set; } + + /// + /// Gets or sets the encrypted data. + /// + public string DecryptedData { get; set; } + + public DecryptionResult() { Errors = new List(); } From 38b7058f288db017479ca98263f3e714a75d324a Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Mon, 19 Feb 2024 00:21:32 +0100 Subject: [PATCH 15/27] feat: add rsa usage class --- src/SafeCrypt.Test/Usage/RsaUsage.cs | 54 ++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/SafeCrypt.Test/Usage/RsaUsage.cs diff --git a/src/SafeCrypt.Test/Usage/RsaUsage.cs b/src/SafeCrypt.Test/Usage/RsaUsage.cs new file mode 100644 index 0000000..177707f --- /dev/null +++ b/src/SafeCrypt.Test/Usage/RsaUsage.cs @@ -0,0 +1,54 @@ +using SafeCrypt.Helpers; +using SafeCrypt.RsaEncryption; +using System.Collections; + +namespace safecrypt_testapp.Usage; + +internal class RsaUsage +{ + internal async void Usage() + { + // Example: Generate RSA keys + var rsaKeyPair = KeyGenerators.GenerateRsaKeys(2048); + + string rsaPublicKey = rsaKeyPair.Item1; + string rsaPrivateKey = rsaKeyPair.Item2; + + Console.WriteLine($"pubic key {rsaPublicKey}"); + Console.WriteLine($"private key {rsaPrivateKey}"); + + // Example: Encrypt and Decrypt using RSA + string originalData = "Hello, RSA Encryption!"; + + var enModel = new RsaEncryptionParameters + { + DataToEncrypt = originalData, + PublicKey = rsaPublicKey, + }; + + var encryptedData = await Rsa.EncryptAsync(enModel); + + Console.WriteLine($"Original Data: {originalData}"); + + Console.WriteLine("Original byte array: " + BitConverter.ToString(encryptedData.EncryptedData)); + string EncryptedDataconvertedString = Convert.ToBase64String(encryptedData.EncryptedData); + + byte[] convertedBytes = Convert.FromBase64String(EncryptedDataconvertedString); + + Console.WriteLine("Converted back to byte array: " + BitConverter.ToString(convertedBytes)); + bool arraysAreEqual = StructuralComparisons.StructuralEqualityComparer.Equals(encryptedData.EncryptedData, convertedBytes); + Console.WriteLine("Original and converted byte arrays are equal: " + arraysAreEqual); + + // Decrypting + var decryptionModel = new RsaDecryptionParameters + { + DataToDecrypt = convertedBytes, + PrivateKey = rsaPrivateKey + }; + + var decryptedData = await Rsa.DecryptAsync(decryptionModel); + Console.WriteLine($"{decryptedData.DecryptedData}"); + + Console.ReadLine(); + } +} From 4b71e03c74c2092add1f7b562c34c4db2cdc18bc Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Mon, 19 Feb 2024 00:21:52 +0100 Subject: [PATCH 16/27] modify RsaEncryptionParameters namespace --- .../RsaEncryption/Models/Encrypt/RsaEncryptionParameters.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/Encrypt/RsaEncryptionParameters.cs b/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/Encrypt/RsaEncryptionParameters.cs index f1c6073..d688ff6 100644 --- a/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/Encrypt/RsaEncryptionParameters.cs +++ b/src/SafeCrypt.Lib/Encryption/RsaEncryption/Models/Encrypt/RsaEncryptionParameters.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace SafeCrypt.RsaEncryption.Models +namespace SafeCrypt.RsaEncryption { public sealed class RsaEncryptionParameters : IEncryptionData { From c1f86002580788ab9762762357143deaa4dbad3a Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Mon, 19 Feb 2024 00:22:17 +0100 Subject: [PATCH 17/27] remove rsa usage from program class --- src/SafeCrypt.Test/Program.cs | 43 +---------------------------------- 1 file changed, 1 insertion(+), 42 deletions(-) diff --git a/src/SafeCrypt.Test/Program.cs b/src/SafeCrypt.Test/Program.cs index 21cd922..8c3518c 100644 --- a/src/SafeCrypt.Test/Program.cs +++ b/src/SafeCrypt.Test/Program.cs @@ -2,10 +2,7 @@ using SafeCrypt.AESDecryption; using SafeCrypt.AESEncryption; -using SafeCrypt.Helpers; using SafeCrypt.Models; -using SafeCrypt.RsaEncryption; -using SafeCrypt.RsaEncryption.Models; var dataToEncrypt = "Data to Encrypt"; var secret = "hghjuytsdfraestwsgtere=="; @@ -39,42 +36,4 @@ Console.WriteLine($"IV key: {decryptionData.Iv}"); Console.WriteLine($"Secret key: {decryptionData.SecretKey}"); - - -/////////////////////////// -/// -// Example: Generate RSA keys -var rsaKeyPair = KeyGenerators.GenerateRsaKeys(2048); -string rsaPublicKey = rsaKeyPair.Item1; -string rsaPrivateKey = rsaKeyPair.Item2; - -Console.WriteLine($"pubic key {rsaPublicKey}"); -Console.WriteLine($"private key {rsaPrivateKey}"); - -// Example: Encrypt and Decrypt using RSA -string originalData = "Hello, RSA Encryption!"; - -var enModel = new RsaEncryptionParameters -{ - DataToEncrypt = originalData, - PublicKey = rsaPublicKey, -}; - -var encryptedData = await Rsa.EncryptAsync(enModel); - -var uccRYTED = new RsaDecryptionParameters -{ - DataToDecrypt = encryptedData.EncryptedData, - PrivateKey = rsaPrivateKey -}; - -var decryptedData = await Rsa.DecryptAsync(uccRYTED); - -// Display results -Console.WriteLine($"Original Data: {originalData}"); -Console.WriteLine($"Encrypted Data: {encryptedData.EncryptedData}"); -//Console.WriteLine($"Encrypted Data-------: {BitConverter.ToString(encryptedData.EncryptedData)}"); -Console.WriteLine($"Decrypted Data: {decryptedData.DecryptedData}"); - - -Console.WriteLine("Hello, World!"); +Console.ReadLine(); From f5d1e26e8dbcc781bb466221ecc9e6c8e84e9219 Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Mon, 19 Feb 2024 00:22:46 +0100 Subject: [PATCH 18/27] feat: update readme doc to reflect rsa implementation --- README.md | 4 +++ Rsa.md | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ SafeCrypt.sln | 6 ++++ 3 files changed, 99 insertions(+) create mode 100644 Rsa.md diff --git a/README.md b/README.md index 6965cd2..c8ba4aa 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ The Encryption library provides a set of methods for encrypting and decrypting d - [Usage](#usage) - [API Reference](#api-reference) - [Examples](#examples) +- [RSA Encryption and Decryption](#rsa) - [Contributing](#contributing) - [License](#license) @@ -121,6 +122,9 @@ class Program } } ``` +## Rsa +For more details on RSA Encryption, check the [Rsa.md](../doc/Rsa.md) document. + ## Contributing diff --git a/Rsa.md b/Rsa.md new file mode 100644 index 0000000..12fe8b7 --- /dev/null +++ b/Rsa.md @@ -0,0 +1,89 @@ +# RSA Encryption and Decryption + +## Overview + +This library provides a straightforward implementation of RSA encryption and decryption in C# using the .NET `RSACryptoServiceProvider`. +It includes methods for generating RSA key pairs, encrypting data with a public key, and decrypting data with a private key. + +## Table of Contents + +- [Usage](#usage) + - [Generate RSA Keys](#generate-rsa-keys) + - [Encrypt and Decrypt using RSA](#encrypt-and-decrypt-using-rsa) + +## Usage + +### Generate RSA Keys + +```csharp +using SafeCrypt.Helpers; + +var rsaKeyPair = KeyGenerators.GenerateRsaKeys(2048); + +string rsaPublicKey = rsaKeyPair.Item1; +string rsaPrivateKey = rsaKeyPair.Item2; + +Console.WriteLine($"Public Key: {rsaPublicKey}"); +Console.WriteLine($"Private Key: {rsaPrivateKey}"); +``` + +### Encrypt and Decrypt using RSA + +```csharp + using SafeCrypt.RsaEncryption; + + // Encrypt + string originalData = "Hello, RSA Encryption!"; + + var encryptionModel = new RsaEncryptionParameters + { + DataToEncrypt = originalData, + PublicKey = rsaPublicKey, + }; + + var encryptedData = await Rsa.EncryptAsync(encryptionModel); + + Console.WriteLine($"Original Data: {originalData}"); + Console.WriteLine("Encrypted Data: " + BitConverter.ToString(encryptedData.EncryptedData)); + + // Convert encrypted byte array to Base64 string + string encryptedDataConvertedString = Convert.ToBase64String(encryptedData.EncryptedData); + + // Convert string back to byte array for decryption + byte[] convertedBytes = Convert.FromBase64String(encryptedDataConvertedString); + + bool arraysAreEqual = StructuralComparisons.StructuralEqualityComparer.Equals(encryptedData.EncryptedData, convertedBytes); + Console.WriteLine("Original and converted byte arrays are equal: " + arraysAreEqual); // should return true + + + + // Decrypt + var decryptionModel = new RsaDecryptionParameters + { + DataToDecrypt = convertedBytes, // encryptedData.EncryptedData + PrivateKey = rsaPrivateKey, + }; + + var decryptedData = await Rsa.DecryptAsync(decryptionModel); + + // if Error occurs during encryption + if (decryptedData.Errors.Count > 0) + { + Console.WriteLine("Decryption Errors:"); + foreach (var error in decryptedData.Errors) + { + Console.WriteLine(error); + } + } + else + { + Console.WriteLine($"Decrypted Data: {decryptedData.DecryptedData}"); + } + +// Note: The return type from Rsa.EncryptAsync is `EncryptionResult`, and Rsa.DecryptAsync is `DecryptionResult`. +// Both models include a list of errors encountered during encryption/decryption. + +``` +## Contributing + +Contributions are welcome! Feel free to open issues, submit pull requests, or provide feedback. \ No newline at end of file diff --git a/SafeCrypt.sln b/SafeCrypt.sln index c639949..84a53ab 100644 --- a/SafeCrypt.sln +++ b/SafeCrypt.sln @@ -13,6 +13,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SafeCrypt", "src\SafeCrypt. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SafeCrypt.App", "src\SafeCrypt.Test\SafeCrypt.App.csproj", "{DAD7FFA3-AABC-47FF-BA79-0C9531BFBBE6}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{632FAE12-6DE3-4B21-ADBB-F5222B35F707}" + ProjectSection(SolutionItems) = preProject + Rsa.md = Rsa.md + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -36,6 +41,7 @@ Global {1D91E775-F63F-4537-B81E-B8F9A6480D6D} = {0B7C0C60-9850-4554-AF85-86C0378B6B16} {AE9FAE54-9854-4F98-A60F-19125CEAA3A8} = {8507D130-9F07-426C-8EE6-0AC714CF72E5} {DAD7FFA3-AABC-47FF-BA79-0C9531BFBBE6} = {1D91E775-F63F-4537-B81E-B8F9A6480D6D} + {632FAE12-6DE3-4B21-ADBB-F5222B35F707} = {0B7C0C60-9850-4554-AF85-86C0378B6B16} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {639A4359-2BA4-4F71-9EBF-D6EAB68C84CB} From 66eafce5ec9d40d54d0fb2d7cff2bf956a88e90b Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Mon, 19 Feb 2024 00:31:00 +0100 Subject: [PATCH 19/27] remove unused code from rsa class --- .../Encryption/RsaEncryption/Rsa.cs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/SafeCrypt.Lib/Encryption/RsaEncryption/Rsa.cs b/src/SafeCrypt.Lib/Encryption/RsaEncryption/Rsa.cs index 81eb84a..22963f4 100644 --- a/src/SafeCrypt.Lib/Encryption/RsaEncryption/Rsa.cs +++ b/src/SafeCrypt.Lib/Encryption/RsaEncryption/Rsa.cs @@ -35,17 +35,11 @@ public static async Task EncryptAsync(RsaEncryptionParameters if(data.Errors.Count > 0) { - // If there are errors in the encryption process, add them to the result and return result.Errors.AddRange(data.Errors); return result; } - // Convert the encrypted data to a hexadecimal string - //result.EncryptedData = data.EncryptedData; - //result.EncryptedData = Convert.ToBase64String(data.EncryptedData); - //result.EncryptedData = BitConverter.ToString(data.EncryptedData); - //result.EncryptedData = Encoding.UTF8.GetString(data.EncryptedData); //Encoding.UTF8.GetString(decryptedData) - result.EncryptedData = data.EncryptedData; //Encoding.UTF8.GetString(decryptedData) + result.EncryptedData = data.EncryptedData; return result; } @@ -53,11 +47,11 @@ public static async Task DecryptAsync(RsaDecryptionParameters { var result = new DecryptionResult(); - //if (string.IsNullOrWhiteSpace(model.DataToDecrypt)) - //{ - // result.Errors.Add($"Data cannot be null {nameof(model.DataToDecrypt)}"); - // return result; - //} + if(model.DataToDecrypt == null) + { + result.Errors.Add($"DataToDecrypt cannot be null {nameof(model.DataToDecrypt)}"); + return result; + } if (string.IsNullOrWhiteSpace(model.PrivateKey)) { @@ -70,7 +64,6 @@ public static async Task DecryptAsync(RsaDecryptionParameters if (data.Errors.Count > 0) { - // if there are errors in the encryption process, add them to the result and return result.Errors.AddRange(data.Errors); return result; } From 996346351d76cf6d20bbb15489a47512ac879069 Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Mon, 19 Feb 2024 00:31:33 +0100 Subject: [PATCH 20/27] mark rsa encryption class as internal --- src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs b/src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs index 6dc57d9..a5cd195 100644 --- a/src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs +++ b/src/SafeCrypt.Lib/Encryption/RsaEncryption/RsaEncryption.cs @@ -6,7 +6,7 @@ namespace SafeCrypt.RsaEncryption { - public static class RsaEncryption + internal static class RsaEncryption { /// /// Asynchronously encrypts the provided data using the RSA (Rivest–Shamir–Adleman) algorithm. From aab63fa262170c7c7a71528261b876c9f403fa2f Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Mon, 19 Feb 2024 00:32:02 +0100 Subject: [PATCH 21/27] marke usage model as internal protected --- src/SafeCrypt.Test/Usage/RsaUsage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SafeCrypt.Test/Usage/RsaUsage.cs b/src/SafeCrypt.Test/Usage/RsaUsage.cs index 177707f..fc4ef22 100644 --- a/src/SafeCrypt.Test/Usage/RsaUsage.cs +++ b/src/SafeCrypt.Test/Usage/RsaUsage.cs @@ -6,7 +6,7 @@ namespace safecrypt_testapp.Usage; internal class RsaUsage { - internal async void Usage() + internal protected async void Usage() { // Example: Generate RSA keys var rsaKeyPair = KeyGenerators.GenerateRsaKeys(2048); From 96107e96a818e2bcde8bb1a55b444ae9fc34eabe Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Mon, 19 Feb 2024 00:36:10 +0100 Subject: [PATCH 22/27] update doc location --- Rsa.md => doc/Rsa.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Rsa.md => doc/Rsa.md (100%) diff --git a/Rsa.md b/doc/Rsa.md similarity index 100% rename from Rsa.md rename to doc/Rsa.md From 3282f502f8ac897975093265fa30162cac6bfecf Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Mon, 19 Feb 2024 00:45:09 +0100 Subject: [PATCH 23/27] feat: update readme doc --- README.md | 21 +++++++++++++-------- SafeCrypt.sln | 6 ------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index c8ba4aa..474bbf1 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,14 @@ A C# library for encryption and decryption. ## Overview -The Encryption library provides a set of methods for encrypting and decrypting data using the Advanced Encryption Standard (AES) algorithm, and other algorithm. It is designed to be easy to use and can be integrated into C# applications that require secure data transmission or storage. - +The SafeCrypt library provides a set of methods for encrypting and decrypting data using various encryption algorithms, +including the Advanced Encryption Standard (AES) and RSA (Rivest�Shamir�Adleman). +It is designed to be easy to use and can be integrated into C# applications that require secure data transmission or storage. ## Table of Contents - [Installation](#installation) -- [Usage](#usage) -- [API Reference](#api-reference) -- [Examples](#examples) -- [RSA Encryption and Decryption](#rsa) +- [AES usage](#usage) +- [RSA Encryption and Decryption usage](#rsa) - [Contributing](#contributing) - [License](#license) @@ -35,9 +34,10 @@ To use the SafeCrypt library in your C# project, follow these steps: Now, you can reference the SafeCrypt library in your C# project. -## Basic Usage +## Usage -To use the library in your C# application, instantiate the `AesEncryption` or `AesDecryption` class and call the provided methods. Here's a simple example: +To use the AES encryption in your C# application, +instantiate the `AesEncryption` or `AesDecryption` class and call the provided methods. Here's a simple example: ```csharp using SafeCrypt.AESDecryption; @@ -122,7 +122,12 @@ class Program } } ``` + + ## Rsa +This library provides a straightforward implementation of RSA encryption and decryption in C# using the .NET `RSACryptoServiceProvider`. +It includes methods for generating RSA key pairs, encrypting data with a public key, and decrypting data with a private key. + For more details on RSA Encryption, check the [Rsa.md](../doc/Rsa.md) document. diff --git a/SafeCrypt.sln b/SafeCrypt.sln index 84a53ab..c639949 100644 --- a/SafeCrypt.sln +++ b/SafeCrypt.sln @@ -13,11 +13,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SafeCrypt", "src\SafeCrypt. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SafeCrypt.App", "src\SafeCrypt.Test\SafeCrypt.App.csproj", "{DAD7FFA3-AABC-47FF-BA79-0C9531BFBBE6}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{632FAE12-6DE3-4B21-ADBB-F5222B35F707}" - ProjectSection(SolutionItems) = preProject - Rsa.md = Rsa.md - EndProjectSection -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -41,7 +36,6 @@ Global {1D91E775-F63F-4537-B81E-B8F9A6480D6D} = {0B7C0C60-9850-4554-AF85-86C0378B6B16} {AE9FAE54-9854-4F98-A60F-19125CEAA3A8} = {8507D130-9F07-426C-8EE6-0AC714CF72E5} {DAD7FFA3-AABC-47FF-BA79-0C9531BFBBE6} = {1D91E775-F63F-4537-B81E-B8F9A6480D6D} - {632FAE12-6DE3-4B21-ADBB-F5222B35F707} = {0B7C0C60-9850-4554-AF85-86C0378B6B16} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {639A4359-2BA4-4F71-9EBF-D6EAB68C84CB} From fc89ae1b5dc41a9378714fa8b49d752c2f4e1e26 Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Mon, 19 Feb 2024 00:48:03 +0100 Subject: [PATCH 24/27] update rsa file location --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 474bbf1..9eefa2e 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ class Program This library provides a straightforward implementation of RSA encryption and decryption in C# using the .NET `RSACryptoServiceProvider`. It includes methods for generating RSA key pairs, encrypting data with a public key, and decrypting data with a private key. -For more details on RSA Encryption, check the [Rsa.md](../doc/Rsa.md) document. +For more details on RSA Encryption, check the [Rsa.md](doc/Rsa.md) document. ## Contributing From 4bac39792f2b047099c868520a397e124959ab34 Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Mon, 19 Feb 2024 00:52:30 +0100 Subject: [PATCH 25/27] add using statement in doc --- doc/Rsa.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/Rsa.md b/doc/Rsa.md index 12fe8b7..0d9a2d0 100644 --- a/doc/Rsa.md +++ b/doc/Rsa.md @@ -17,6 +17,7 @@ It includes methods for generating RSA key pairs, encrypting data with a public ```csharp using SafeCrypt.Helpers; +using SafeCrypt.RsaEncryption; var rsaKeyPair = KeyGenerators.GenerateRsaKeys(2048); From 7487fdab40c14b24a73c9fb64dbf4a7d0d8afeb8 Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Mon, 19 Feb 2024 00:52:56 +0100 Subject: [PATCH 26/27] chnage rsausage class namespace --- src/SafeCrypt.Test/Usage/RsaUsage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SafeCrypt.Test/Usage/RsaUsage.cs b/src/SafeCrypt.Test/Usage/RsaUsage.cs index fc4ef22..b9bb1ad 100644 --- a/src/SafeCrypt.Test/Usage/RsaUsage.cs +++ b/src/SafeCrypt.Test/Usage/RsaUsage.cs @@ -2,7 +2,7 @@ using SafeCrypt.RsaEncryption; using System.Collections; -namespace safecrypt_testapp.Usage; +namespace SafeCrypt.App.Usage; internal class RsaUsage { From de1b13d811cab784ff3df322f50f31dd022a9985 Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Mon, 19 Feb 2024 00:53:22 +0100 Subject: [PATCH 27/27] update readme file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9eefa2e..a27e036 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ It is designed to be easy to use and can be integrated into C# applications that ## Table of Contents - [Installation](#installation) -- [AES usage](#usage) +- [AES Encryption and Decryption usage](#usage) - [RSA Encryption and Decryption usage](#rsa) - [Contributing](#contributing) - [License](#license)