Medusa.net/Medusa.Core/Utils/DESEncryption.cs
2024-08-15 20:06:56 +02:00

36 lines
1016 B
C#

using System.Security.Cryptography;
namespace Medusa.Core.Utils
{
public class DESEncryption(byte[] key)
{
private readonly byte[] Key = key;
public byte[] Encrypt(byte[] data)
{
using var tripleDES = TripleDES.Create();
tripleDES.Key = Key;
tripleDES.Mode = CipherMode.CBC;
tripleDES.Padding = PaddingMode.None;
tripleDES.IV = new byte[8];
using var encryptor = tripleDES.CreateEncryptor();
return encryptor.TransformFinalBlock(data, 0, data.Length);
}
public byte[] Decrypt(byte[] data)
{
using var tripleDES = TripleDES.Create();
tripleDES.Key = Key;
tripleDES.Mode = CipherMode.CBC;
tripleDES.Padding = PaddingMode.None;
tripleDES.IV = new byte[8];
using var decryptor = tripleDES.CreateDecryptor();
return decryptor.TransformFinalBlock(data, 0, data.Length);
}
}
}