-
Notifications
You must be signed in to change notification settings - Fork 10
/
Encryptor.cs
49 lines (44 loc) · 1.48 KB
/
Encryptor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
using System;
using Rijndael256;
namespace EasyPipes
{
/// <summary>
/// Provides 256-bit symmetric AES encryption and decryption for TCP communication
/// </summary>
public class Encryptor
{
/// <summary>
/// The encryption key
/// </summary>
protected string EncryptionKey { get; private set; }
/// <summary>
/// Constructor
/// </summary>
/// <param name="key">The encryption key</param>
public Encryptor(string key)
{
EncryptionKey = key;
}
/// <summary>
/// Decrypt a binary blob
/// </summary>
/// <param name="msg">The binary "ciphertext" with IV and MAC</param>
/// <returns>The binary "plaintext"</returns>
public byte[] DecryptMessage(byte[] msg)
{
return RijndaelEtM.DecryptBinary(msg, EncryptionKey, KeySize.Aes256);
}
/// <summary>
/// Encrypt a binary blob
/// </summary>
/// <param name="msg">The binary "plaintext"</param>
/// <returns>The binary "ciphertext" with IV and MAC</returns>
public byte[] EncryptMessage(byte[] msg)
{
return RijndaelEtM.EncryptBinary(msg, EncryptionKey, KeySize.Aes256);
}
}
}