‪Black Box
BBThermostatDataDecryption.cs
Go to the documentation of this file.
1 /*
2 * FILE : BBthermostatDataDecryption.cs
3 * PROJECT : Black Box
4 * PROGRAMMER : BRIAN HINDS
5 * FIRST VERSION : 1.0.0.0
6 * DESCRIPTION : This library file manage the decryption of the thermostat data.
7 */
8 
9 using System;
10 using System.IO;
11 using System.Security.Cryptography;
12 using System.Text;
13 
15 {
17  {
20  private static string ‪pSensor = "";
21 
24  private static byte[] ‪SensorIVByte = { };
25  private static byte[] ‪SensorKeyByte = { };
26  private static byte[] ‪inputByteArray;
27  private static MemoryStream ‪ms = null;
28  private static CryptoStream ‪cs = null;
29 
35  public static string ‪DecryptData(string SensorData)
36  {
37  ‪SensorIVByte = Encoding.UTF8.GetBytes(‪SensorIV.Substring(0, 8));
38  ‪SensorKeyByte = Encoding.UTF8.GetBytes(‪SensorKey.Substring(0, 8));
39 
40  ‪inputByteArray = new byte[SensorData.Replace(" ", "+").Length];
41  ‪inputByteArray = Convert.FromBase64String(SensorData.Replace(" ", "+"));
42  using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
43  {
44  ‪ms = new MemoryStream();
45  ‪cs = new CryptoStream(‪ms, des.CreateDecryptor(‪SensorKeyByte, ‪SensorIVByte), CryptoStreamMode.Write);
46  ‪cs.Write(‪inputByteArray, 0, ‪inputByteArray.Length);
47  ‪cs.FlushFinalBlock();
48  Encoding encoding = Encoding.UTF8;
49  ‪pSensor = encoding.GetString(‪ms.ToArray());
50  }
51 
52  return ‪pSensor;
53  }
54  }
55 }
‪static string DecryptData(string SensorData)
‪This method decrypt the saved thermostat data