3 using System.Security.Cryptography;
6 namespace SpeedportHybridControl.Implementations
8 public static class Cryptography
10 private static string KEY = "8E16A57381AFDA47856682CEBE85DCF5982F59321AE28B2822C1C9E1FC481C50";
11 private static string IV = "7CD37E78623793D4C4BB81DB73B08522";
13 public static string Encrypt(string clearText)
15 byte[] clearBytes = Encoding.Unicode.GetBytes(clearText);
17 using (Aes encryptor = Aes.Create())
19 if (Object.Equals(encryptor, null))
25 encryptor.KeySize = 256;
26 encryptor.BlockSize = 128;
27 encryptor.Mode = CipherMode.CBC;
28 encryptor.Padding = PaddingMode.PKCS7;
29 encryptor.Key = util.HexToByte(KEY);
30 encryptor.IV = util.HexToByte(IV);
32 using (MemoryStream ms = new MemoryStream())
34 using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
36 cs.Write(clearBytes, 0, clearBytes.Length);
39 clearText = Convert.ToBase64String(ms.ToArray());
46 public static string Decrypt(string cipherText)
48 byte[] cipherBytes = Convert.FromBase64String(cipherText);
50 using (Aes encryptor = Aes.Create())
52 if (Object.Equals(encryptor, null))
58 encryptor.KeySize = 256;
59 encryptor.BlockSize = 128;
60 encryptor.Mode = CipherMode.CBC;
61 encryptor.Padding = PaddingMode.PKCS7;
62 encryptor.Key = util.HexToByte(KEY);
63 encryptor.IV = util.HexToByte(IV);
65 using (MemoryStream ms = new MemoryStream())
67 using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
69 cs.Write(cipherBytes, 0, cipherBytes.Length);
72 cipherText = Encoding.Unicode.GetString(ms.ToArray());