Skip to content

Commit fe96242

Browse files
committed
Main encryption class seperated
1 parent a5fba13 commit fe96242

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.IO;
3+
using System.Security.Cryptography;
4+
5+
namespace SafeCrypt
6+
{
7+
public class BaseAesEncryption
8+
{
9+
// Method to encrypt data using AES algorithm
10+
public virtual byte[] EncryptAES(byte[] data, byte[] key, byte[] iv)
11+
{
12+
try
13+
{
14+
using (Aes aes = Aes.Create())
15+
{
16+
aes.Key = key;
17+
aes.IV = iv;
18+
ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);
19+
using (MemoryStream memoryStream = new MemoryStream())
20+
{
21+
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
22+
{
23+
cryptoStream.Write(data, 0, data.Length);
24+
cryptoStream.FlushFinalBlock();
25+
26+
return memoryStream.ToArray();
27+
}
28+
}
29+
}
30+
}
31+
catch (Exception ex)
32+
{
33+
throw;
34+
}
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)