Пример #1
0
        public bool EncodeText(string text)
        {
            try
            {
                Clear();

                if (!string.IsNullOrEmpty(text))
                {
                    Text        = text;
                    Binary      = TranslatorHelper.TextToBinary(text);
                    Hexadecimal = TranslatorHelper.TextToHexadecimal(text);
                    ASCII       = TranslatorHelper.TextToASCII(text);
                    Base64      = TranslatorHelper.TextToBase64(text);
                    CRC32       = TranslatorHelper.TextToHash(text, HashType.CRC32, true);
                    MD5         = TranslatorHelper.TextToHash(text, HashType.MD5, true);
                    SHA1        = TranslatorHelper.TextToHash(text, HashType.SHA1, true);
                    SHA256      = TranslatorHelper.TextToHash(text, HashType.SHA256, true);
                    SHA384      = TranslatorHelper.TextToHash(text, HashType.SHA384, true);
                    SHA512      = TranslatorHelper.TextToHash(text, HashType.SHA512, true);
                    return(true);
                }
            }
            catch
            {
            }

            return(false);
        }
Пример #2
0
        public bool DecodeBase64(string base64)
        {
            try
            {
                Text = TranslatorHelper.Base64ToText(base64);
                return(!string.IsNullOrEmpty(Text));
            }
            catch
            {
            }

            Text = null;
            return(false);
        }
Пример #3
0
        public bool DecodeASCII(string ascii)
        {
            try
            {
                Text = TranslatorHelper.ASCIIToText(ascii);
                return(!string.IsNullOrEmpty(Text));
            }
            catch
            {
            }

            Text = null;
            return(false);
        }
Пример #4
0
        public bool DecodeHex(string hex)
        {
            try
            {
                Text = TranslatorHelper.HexadecimalToText(hex);
                return(!string.IsNullOrEmpty(Text));
            }
            catch
            {
            }

            Text = null;
            return(false);
        }
Пример #5
0
        public bool DecodeBinary(string binary)
        {
            try
            {
                Text = TranslatorHelper.BinaryToText(binary);
                return(!string.IsNullOrEmpty(Text));
            }
            catch
            {
            }

            Text = null;
            return(false);
        }
Пример #6
0
        private string HashCheckThread(string filePath, HashType hashType, IProgress <float> progress, CancellationToken ct)
        {
            using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (HashAlgorithm hash = GetHashAlgorithm(hashType))
                    using (CryptoStream cs = new CryptoStream(stream, hash, CryptoStreamMode.Read))
                    {
                        long      bytesRead, totalRead = 0;
                        byte[]    buffer = new byte[8192];
                        Stopwatch timer  = Stopwatch.StartNew();

                        while ((bytesRead = cs.Read(buffer, 0, buffer.Length)) > 0 && !ct.IsCancellationRequested)
                        {
                            totalRead += bytesRead;

                            if (timer.ElapsedMilliseconds > 200)
                            {
                                float percentage = (float)totalRead / stream.Length * 100;
                                progress.Report(percentage);

                                timer.Reset();
                                timer.Start();
                            }
                        }

                        if (ct.IsCancellationRequested)
                        {
                            progress.Report(0);

                            ct.ThrowIfCancellationRequested();
                        }
                        else
                        {
                            progress.Report(100);

                            string[] hex = TranslatorHelper.BytesToHexadecimal(hash.Hash);
                            return(string.Concat(hex));
                        }
                    }

            return(null);
        }
Пример #7
0
        private void CheckThread(object sender, DoWorkEventArgs e)
        {
            using (FileStream stream = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (HashAlgorithm hash = GetHashAlgorithm(HashType))
                    using (CryptoStream cs = new CryptoStream(stream, hash, CryptoStreamMode.Read))
                    {
                        long      bytesRead, totalRead = 0;
                        byte[]    buffer = new byte[8192];
                        Stopwatch timer  = Stopwatch.StartNew();

                        while ((bytesRead = cs.Read(buffer, 0, buffer.Length)) > 0 && !bw.CancellationPending)
                        {
                            totalRead += bytesRead;

                            if (timer.ElapsedMilliseconds > 200)
                            {
                                float progress = (float)totalRead / stream.Length * 100;
                                bw.ReportProgress(0, progress);
                                timer.Reset();
                                timer.Start();
                            }
                        }

                        if (bw.CancellationPending)
                        {
                            bw.ReportProgress(0, 0f);
                            e.Cancel = true;
                        }
                        else
                        {
                            bw.ReportProgress(0, 100f);
                            string[] hex = TranslatorHelper.BytesToHexadecimal(hash.Hash);
                            e.Result = string.Concat(hex);
                        }
                    }
        }
Пример #8
0
        public bool DecodeBase64(string base64)
        {
            string result = TranslatorHelper.Base64ToText(base64);

            return(EncodeText(result));
        }
Пример #9
0
        public bool DecodeASCII(string ascii)
        {
            string result = TranslatorHelper.ASCIIToText(ascii);

            return(EncodeText(result));
        }
Пример #10
0
        public bool DecodeHex(string hex)
        {
            string result = TranslatorHelper.HexadecimalToText(hex);

            return(EncodeText(result));
        }
Пример #11
0
        public bool DecodeBinary(string binary)
        {
            string result = TranslatorHelper.BinaryToText(binary);

            return(EncodeText(result));
        }