Skip to content

Commit 3f04900

Browse files
committed
feat: test rsa algorithms
1 parent dcc1b7e commit 3f04900

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

src/SafeCrypt.Test/Program.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
using SafeCrypt.AESDecryption;
44
using SafeCrypt.AESEncryption;
5+
using SafeCrypt.Helpers;
56
using SafeCrypt.Models;
7+
using SafeCrypt.RsaEncryption;
8+
using SafeCrypt.RsaEncryption.Models;
69

710
var dataToEncrypt = "Data to Encrypt";
811
var secret = "hghjuytsdfraestwsgtere==";
@@ -37,4 +40,41 @@
3740
Console.WriteLine($"Secret key: {decryptionData.SecretKey}");
3841

3942

43+
44+
///////////////////////////
45+
///
46+
// Example: Generate RSA keys
47+
var rsaKeyPair = KeyGenerators.GenerateRsaKeys(2048);
48+
string rsaPublicKey = rsaKeyPair.Item1;
49+
string rsaPrivateKey = rsaKeyPair.Item2;
50+
51+
Console.WriteLine($"pubic key {rsaPublicKey}");
52+
Console.WriteLine($"private key {rsaPrivateKey}");
53+
54+
// Example: Encrypt and Decrypt using RSA
55+
string originalData = "Hello, RSA Encryption!";
56+
57+
var enModel = new RsaEncryptionParameters
58+
{
59+
DataToEncrypt = originalData,
60+
PublicKey = rsaPublicKey,
61+
};
62+
63+
var encryptedData = await Rsa.EncryptAsync(enModel);
64+
65+
var uccRYTED = new RsaDecryptionParameters
66+
{
67+
DataToDecrypt = encryptedData.EncryptedData,
68+
PrivateKey = rsaPrivateKey
69+
};
70+
71+
var decryptedData = await Rsa.DecryptAsync(uccRYTED);
72+
73+
// Display results
74+
Console.WriteLine($"Original Data: {originalData}");
75+
Console.WriteLine($"Encrypted Data: {encryptedData.EncryptedData}");
76+
//Console.WriteLine($"Encrypted Data-------: {BitConverter.ToString(encryptedData.EncryptedData)}");
77+
Console.WriteLine($"Decrypted Data: {decryptedData.DecryptedData}");
78+
79+
4080
Console.WriteLine("Hello, World!");

0 commit comments

Comments
 (0)