‪Black Box
BBSensorDataDecryption.cs
Go to the documentation of this file.
1 /*
2 * FILE : BBSensorDataDecrytion.cs
3 * PROJECT : Black Box
4 * PROGRAMMER : BRIAN HINDS
5 * FIRST VERSION : 1.0.0.0
6 * DATE : March 20, 2019
7 * DESCRIPTION : This file manages the decryption of the collected data.
8 */
9 
10 using System;
11 using System.IO;
12 using System.Security.Cryptography;
13 using System.Text;
14 
16 {
18  {
19  #region Variables
20 
21  private static string ‪pSensor = "";
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 
30  #endregion Variables
31 
32  #region Data Decryption
33 
39  public static string ‪DecryptData(string SensorData)
40  {
41  ‪SensorIVByte = Encoding.UTF8.GetBytes(‪SensorIV.Substring(0, 8));
42  ‪SensorKeyByte = Encoding.UTF8.GetBytes(‪SensorKey.Substring(0, 8));
43 
44  ‪inputByteArray = new byte[SensorData.Replace(" ", "+").Length];
45  ‪inputByteArray = Convert.FromBase64String(SensorData.Replace(" ", "+"));
46  using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
47  {
48  ‪ms = new MemoryStream();
49  ‪cs = new CryptoStream(‪ms, des.CreateDecryptor(‪SensorKeyByte, ‪SensorIVByte), CryptoStreamMode.Write);
50  ‪cs.Write(‪inputByteArray, 0, ‪inputByteArray.Length);
51  ‪cs.FlushFinalBlock();
52  Encoding encoding = Encoding.UTF8;
53  ‪pSensor = encoding.GetString(‪ms.ToArray());
54  }
55 
56  return ‪pSensor;
57  }
58 
59  #endregion Data Decryption
60  }
61 }
‪static string DecryptData(string SensorData)
‪This method decrypt the sensor data