public static void LoadStrings() { byte[] stringByteArray; // Stores the current executing assembly and stores it in a variable. Assembly currentAssembly = Assembly.GetExecutingAssembly(); // TODO: Encrypt the string here as it is skipped. string stringResourceName = currentAssembly.GetManifestResourceNames() .Aggregate("", (current, s) => (s == ByteGuardHelper.GetMd5(current) ? s : current)); // Creates a stream using the embedded resource in the current assembly. using (Stream resourceStream = currentAssembly.GetManifestResourceStream(stringResourceName))//BYTEGUARDRESOURCESTRINGPADDINGBYTEGUARD")) { // Resizes the 'StringByteArray' to the correct size. stringByteArray = new byte[resourceStream.Length]; // Reads the bytes from the embedded resource into the 'StringByteArray'. resourceStream.Read(stringByteArray, 0, stringByteArray.Length); } // Decompresses the compressed bytes. //if (DecompressEmbeddedStrings()) stringByteArray = ByteGuardHelper.GzipDecompressBytes(stringByteArray); stringByteArray = AesDecrypt(stringByteArray, (stringResourceName + ByteGuardHelper.GetMd5(K))); B = stringByteArray; }
private static void GetDecryptionKey() { // Adds the required data values to a NameValueCollection ready to be submitted. NameValueCollection dataValues = new NameValueCollection { { "pid", GetProgramId() }, //{"csm", ByteGuardHelper.GetMd5(null, File.ReadAllBytes(Assembly.GetExecutingAssembly().Location))}, { "csm", "00000111112222233333444445555566" }, { "ver", GetProgramVersion() } }; // TODO: GetFileChecksum(File.ReadAllBytes(Assembly.GetExecutingAssembly().Location))); // Submits the required information to download the correct decryption key. if (!SubmitData("byteguard", dataValues)) { Environment.Exit(0); } if (WebResponse.Split('[', ']')[1] == "SUCCESS") { SetCookieContainer(false); // If the submitted file checksum matches the checksum in the database, return the decryption key. DecryptionKey = WebResponse.Replace("[SUCCESS] ", String.Empty); if ((DecryptionKey = ByteGuardHelper.GetMd5(DecryptionKey)) != null) { ByteGuardStringProtections.K = DecryptionKey; ByteGuardConstantProtections.K = DecryptionKey; Authenticated(); } else { MessageBox.Show("Error downloading program data.", "ByteGuard Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SetCookieContainer(true); } } else { // If the submitted file checksum does NOT match the checksum in the database, display the returned error and exit. MessageBox.Show(WebResponse.Replace("[ERROR] ", String.Empty), "ByteGuard Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SetCookieContainer(true); } }
// TODO: Encrypt offline strings. // TODO: Use MD5 hash of all offline strings to protect online strings? public static void LoadStringsOffline() { byte[] stringByteArray; // Get the currently executing assembly and stores it in a variable. Assembly currentAssembly = Assembly.GetExecutingAssembly(); string stringResourceName = currentAssembly.GetManifestResourceNames() .Aggregate("", (current, s) => (s == ByteGuardHelper.GetMd5(current) ? s : current)); using (Stream resourceStream = currentAssembly.GetManifestResourceStream(stringResourceName)) { // Resizes the 'stringByteArray' to the correct size. stringByteArray = new byte[resourceStream.Length]; // Reads the bytes from the embdded resource into the 'stringByteArray'. resourceStream.Read(stringByteArray, 0, stringByteArray.Length); } stringByteArray = ByteGuardHelper.GzipDecompressBytes(stringByteArray); O = stringByteArray; }
public static void LoadIntegers() { // Stores the current executing assembly and stores it in a variable. Assembly currentAssembly = Assembly.GetExecutingAssembly(); string resourceName = currentAssembly.GetManifestResourceNames() .Aggregate("", (current, s) => (s == ByteGuardHelper.GetMd5(current) ? s : current)); // Creates a stream using the embedded resource in the current assembly. using (Stream resourceStream = currentAssembly.GetManifestResourceStream(resourceName)) { // Resizes the 'StringByteArray' to the correct size. B = new byte[resourceStream.Length]; // Reads the bytes from the embedded resource into the 'StringByteArray'. resourceStream.Read(B, 0, B.Length); } B = ByteGuardStringProtections.AesDecrypt( ByteGuardHelper.GzipDecompressBytes(B), (resourceName + ByteGuardHelper.GetMd5(K))); //B = ByteGuardStringProtections.AesDecrypt(B, key); }