Skip to content

Commit 8d40706

Browse files
committed
added correct encryptor file
chunks to 128 bit chunks with CBC mode
1 parent a9efffd commit 8d40706

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/Backend/Encryptor.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.IO;
7+
using System.Security.Cryptography;
8+
9+
namespace Encryption_App
10+
{
11+
class Encryptor
12+
{
13+
public void SymEncrypt(string Data)
14+
{
15+
16+
}
17+
18+
public void SymEncrypt(byte[] bArray, byte[] pwdBytes)
19+
{
20+
byte[] encryptedBytes = null;
21+
22+
// Set your salt here, change it to meet your flavor:
23+
// The salt bytes must be at least 8 bytes.
24+
byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
25+
26+
using (MemoryStream ms = new MemoryStream())
27+
{
28+
using (RijndaelManaged AES = new RijndaelManaged())
29+
{
30+
AES.KeySize = 256;
31+
AES.BlockSize = 128;
32+
33+
var key = new Rfc2898DeriveBytes(pwdBytes, saltBytes, 1000);
34+
AES.Key = key.GetBytes(AES.KeySize / 8);
35+
AES.IV = key.GetBytes(AES.BlockSize / 8);
36+
37+
AES.Mode = CipherMode.CBC;
38+
39+
using (var cs = new CryptoStream(ms, AES.CreateEncryptor(), CryptoStreamMode.Write))
40+
{
41+
cs.Write(bArray, 0, bArray.Length);
42+
cs.Close();
43+
}
44+
encryptedBytes = ms.ToArray();
45+
}
46+
}
47+
48+
49+
}
50+
51+
}
52+
}

0 commit comments

Comments
 (0)