3 using System.Security.Cryptography;
6 namespace SpeedportHybridControl.Implementations {
7 public static class Cryptography {
8 private static string KEY = "8E16A57381AFDA47856682CEBE85DCF5982F59321AE28B2822C1C9E1FC481C50";
9 private static string IV = "7CD37E78623793D4C4BB81DB73B08522";
11 public static string Encrypt (string clearText) {
12 byte[] clearBytes = Encoding.Unicode.GetBytes(clearText);
14 using (Aes encryptor = Aes.Create()) {
15 if (Object.Equals(encryptor, null)) {
20 encryptor.KeySize = 256;
21 encryptor.BlockSize = 128;
22 encryptor.Mode = CipherMode.CBC;
23 encryptor.Padding = PaddingMode.PKCS7;
24 encryptor.Key = util.HexToByte(KEY);
25 encryptor.IV = util.HexToByte(IV);
27 using (MemoryStream ms = new MemoryStream()) {
28 using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write)) {
29 cs.Write(clearBytes, 0, clearBytes.Length);
32 clearText = Convert.ToBase64String(ms.ToArray());
39 public static string Decrypt (string cipherText) {
40 byte[] cipherBytes = Convert.FromBase64String(cipherText);
42 using (Aes encryptor = Aes.Create()) {
43 if (Object.Equals(encryptor, null)) {
48 encryptor.KeySize = 256;
49 encryptor.BlockSize = 128;
50 encryptor.Mode = CipherMode.CBC;
51 encryptor.Padding = PaddingMode.PKCS7;
52 encryptor.Key = util.HexToByte(KEY);
53 encryptor.IV = util.HexToByte(IV);
55 using (MemoryStream ms = new MemoryStream()) {
56 using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write)) {
57 cs.Write(cipherBytes, 0, cipherBytes.Length);
60 cipherText = Encoding.Unicode.GetString(ms.ToArray());