Skip to content

Commit ea99cd0

Browse files
committed
All methods should use the namespace Using SafeCrypt.Encrypt
1 parent bec6572 commit ea99cd0

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Encrypt/Encrypt.cs

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

0 commit comments

Comments
 (0)