using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Security.Cryptography;

namespace Access_Control_Server
{
    class Crypto
    {
        private Byte[] key = {
                         0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,    
                         0x21, 0x43, 0x65, 0x87, 0xa9, 0xcb, 0xed, 0x0f    
                     };

        internal Byte[] EncryptAES(String input)
        {
            Byte[] inBytes = Encoding.UTF8.GetBytes(input);

            AesCryptoServiceProvider aes = new AesCryptoServiceProvider();
            aes.KeySize = 128;
            aes.Key = key;
            aes.Mode = CipherMode.ECB;

            ICryptoTransform encryptor = aes.CreateEncryptor();

            Byte[] output = encryptor.TransformFinalBlock(inBytes, 0, inBytes.Length);
            aes.Clear();

            return output;
        }

        internal String DecryptAES(Byte[] input)
        {
            AesCryptoServiceProvider aes = new AesCryptoServiceProvider();
            aes.KeySize = 128;
            aes.Key = key;
            aes.Mode = CipherMode.ECB;
            aes.Padding = PaddingMode.Zeros;

            ICryptoTransform decryptor = aes.CreateDecryptor();

            Byte[] output = decryptor.TransformFinalBlock(input, 0, 32);
            aes.Clear();

            return Encoding.UTF8.GetString(output).Trim('\0');
        }
    }
}
