Exemplo n.º 1
0
        private static byte[] LoadFileAndDecrypt(string filePath)
        {
            try
            {
                if (File.Exists(filePath))
                {
                    var cipherBytes = File.ReadAllBytes(filePath);
                    return(DecryptBytes(cipherBytes));
                }
            }
            catch (Exception ex)
            {
                UiMessages.Error($"Decryption error:\n\n{ex}");
            }

            //default
            return(null);
        }
Exemplo n.º 2
0
        public static byte[] DecryptBytes(byte[] cipherBytes, bool dumpTarGz = true)
        {
            try
            {
                var decryptedBytes = CryptoHandler.Decrypt(cipherBytes, Password);

                if (dumpTarGz)
                {
                    File.WriteAllBytes(@"config.tar.gz", decryptedBytes);
                }

                return(decryptedBytes);
            }
            catch (Exception ex)
            {
                UiMessages.Error($"Decryption error:\n\n{ex}");
            }

            //default
            return(null);
        }
Exemplo n.º 3
0
        private static bool IsEncrypted(this byte[] data)
        {
            try
            {
                //OpenSSL-encrypted files usually include this text prefix before the encrypted buffer
                const string prefix        = @"Salted__";
                var          prefixLength  = prefix.Length;
                var          relevantBytes = new byte[prefixLength];
                Buffer.BlockCopy(data, 0, relevantBytes, 0, prefixLength);

                var prefixData = Encoding.Default.GetString(relevantBytes);

                return(prefixData == prefix);
            }
            catch (Exception ex)
            {
                UiMessages.Error($"Determination error:\n\n{ex}");
            }

            //default
            return(false);
        }
Exemplo n.º 4
0
        private static byte[] DecompressGzBytes(byte[] gzBytes)
        {
            try
            {
                byte[] decompressedBytes;
                using (var rawStream = new MemoryStream(gzBytes))
                {
                    using (var decompressionStream = new GZipStream(rawStream, CompressionMode.Decompress))
                    {
                        var ms = new MemoryStream();
                        decompressionStream.CopyTo(ms);
                        decompressedBytes = ms.ToArray();
                    }
                }

                return(decompressedBytes);
            }
            catch (Exception ex)
            {
                UiMessages.Error($"Decompression failed!\n\n{ex}");
                return(null);
            }
        }