File tree Expand file tree Collapse file tree
src/SafeCrypt.Lib/Encryption/RsaEncryption Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22using System . Text ;
33using System ;
44using System . Threading . Tasks ;
5+ using SafeCrypt . RsaEncryption . Models ;
56
67namespace SafeCrypt . RsaEncryption
78{
@@ -29,18 +30,30 @@ public static Tuple<string, string> GenerateRsaKeys(int keySize)
2930 /// <param name="data">The data to be encrypted.</param>
3031 /// <param name="publicKey">The RSA public key.</param>
3132 /// <returns>The encrypted data.</returns>
32- public static async Task < byte [ ] > EncryptAsync ( string data , string publicKey )
33+ public static async Task < RsaEncryptionResult > EncryptAsync ( string data , string publicKey )
3334 {
35+ var result = new RsaEncryptionResult ( ) ;
3436
35- return await Task . Run ( ( ) => {
36- using ( var rsa = new RSACryptoServiceProvider ( ) )
37+ try
38+ {
39+ var encryptedData = await Task . Run ( ( ) =>
3740 {
38- rsa . FromXmlString ( publicKey ) ;
39- byte [ ] dataBytes = Encoding . UTF8 . GetBytes ( data ) ;
40- byte [ ] encryptedData = rsa . Encrypt ( dataBytes , false ) ;
41- return encryptedData ;
42- }
43- } ) ;
41+ using ( var rsa = new RSACryptoServiceProvider ( ) )
42+ {
43+ rsa . FromXmlString ( publicKey ) ;
44+ byte [ ] dataBytes = Encoding . UTF8 . GetBytes ( data ) ;
45+ return rsa . Encrypt ( dataBytes , false ) ;
46+ }
47+ } ) ;
48+
49+ result . EncryptedData = encryptedData ;
50+ }
51+ catch ( Exception ex )
52+ {
53+ result . Errors . Add ( ex . Message ) ;
54+ }
55+
56+ return result ;
4457 }
4558
4659 /// <summary>
You can’t perform that action at this time.
0 commit comments