|
2 | 2 |
|
3 | 3 | using SafeCrypt.AESDecryption; |
4 | 4 | using SafeCrypt.AESEncryption; |
| 5 | +using SafeCrypt.Helpers; |
5 | 6 | using SafeCrypt.Models; |
| 7 | +using SafeCrypt.RsaEncryption; |
| 8 | +using SafeCrypt.RsaEncryption.Models; |
6 | 9 |
|
7 | 10 | var dataToEncrypt = "Data to Encrypt"; |
8 | 11 | var secret = "hghjuytsdfraestwsgtere=="; |
|
37 | 40 | Console.WriteLine($"Secret key: {decryptionData.SecretKey}"); |
38 | 41 |
|
39 | 42 |
|
| 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 | + |
40 | 80 | Console.WriteLine("Hello, World!"); |
0 commit comments