Example #1
0
        private static void GetKeyByPassword(int regime, byte[] bytes, out byte[] key)
        {
            SHA3 sha = new SHA3(bytes.Length);

            if (regime < 10)
            {
                sha.useOldDuplex = true;
            }

            int pc  = 4;
            var oiv = regime >= 20 ?
                      Convert.FromBase64String("dm1gZGxLOObGEsQBBg09Nuhi1dnMdzue40B2cvfvff10nVbQQ7JwSvhtZfiJbnFoCG492Us7jPAMnWvYl5RYCsQSUS5TIZ8+7p3chQ7/SpclDR7MGHqCl6T/6LN7ikfVngdI1vZlCrQHDNB4yBynQwRLlMk0puvedDKJLOOcfu40R6/QezEIW3WpPU9qeVYzgwvhbfRrc6wP7WxWMR09Nh97ciY2io+FZ0fsQpCno25ptAIH1dzb1w2DbVLaqF03qz873LLBaHyNdH+4PN92sG9iJ+pOmAQGF/+Jq+TtOdO2TwnAv33rspm6aFpDaKQh4MpNPIhOZct8OhFIQs5r/L5kTNL+McswrZZXPUrWddmrETjMh7ZZ5SeudyfUvJT1MLOUO/K6b6YtGb0pq9VZ4W3K0vhlQBxzSh6ghoFzWCYkG+yNj6vF5iyBjW9R2PCy03lHNbfIy4X8LzAuMjCfxE4Rq7XiT4JcYRHRYXX+NDN2hQtaerzor4FzHJZGyvabz4Ob9+7lCHffL/DysHW660VcmiyZzoxsdM18/JnebllOmKBqJwR/GSci8hTuXca8eZ4TDnL/wJOPA5UOB8yqQ7uGFnfjHIY2Jq7Pyvfd9DingIMe0lkQMG+r6lPVjzxxwjyQ/xXXI7EYyAsD0HllrlcoACwWbLMLnQ3pe36Nl8RbEY3eftn9I7HwdtgfAsmTaxc7NAl2yetAHdf/iUZBUJ6mjKm8/2LeQZI1bxVVygVUZsTEDW1QZrXXEooIeTepxJaZSI8EMKLI9QTu3AEydto35MsD6DKN17jZnWoNXpC/USddnas25ZgtOZrNepPpSHzm+yociIf8sh8R6GwJjueapXP6HfvYQD+8rVOeVwDnjIKEZU2sV/PpQqrm7JgfT0MqehhxCSm8hvooCqW6WfNnCvUVFDRC4F/KD7douO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gbOuDvhlYmeqddZwHAW6b1wqO93/E9SO7Isi/ngVlgEq5F9jQRPo/MrQdvAlJ4d9+Gq0ANqSTVU7mO08tmVhpTaVf0kxTs3pmfcPFvBsmg+7QXltsNl3xtHcfoPa0+RNC8UJO8WVVck+hJlproNtr/KcUCkfWY/CkkorBaCLrD9Wo0WTy2O3wCfJrcLLT8Rdkl4nk6B3FncfdBWfRyjMpocbxaVieCO5sFnCibTZIuYxxVRsd+NBBTBXifrVSkrYrHBidWgnnyMvNuRyTNodLO1AWEcX9QK2l2xlJPlvAFkQhYAv4ef+XDttRf09MjmJP44k7tIolOV3gGTFGgRToKXk5nlSXvXy8q0R42YOjhvzvOQ7AeYoI/bQ38p9cK3qu/5Di4Spjqn+B+oBoXai74LgQEmA5BdgyVC/hfdhfv47AclCoHbXIWZ+HDIUpRtQzIY9YoHtZaic/ern68niLVe0sOzeX7c2LrUsBIf6QhwZIlU5GSuoSl5m+zCGh6p3xflwd/gNd08QlIgmbE4G6aOqYB09uDjGho7VfY3Gy8qjzMjCzTSdeRc/ahbreVZUBGMqhS2TgdBoJu5u1+gnY5B320b44Ni61RFn1fKCaHMbYCJ4xusy8VzkcXmJFPqgY+0unSM3GXg5RQUx0DhOb+sdy7/7ocf+TpmOJFYSQYPsqsuqrfj27xDWiKjfRV/YyRC2BOsdItZn")
                                    : new UTF8Encoding().GetBytes("passwordJjVjRyjcWwo7761qPBQUb3Sx8DACNpassword");
            var dk = 1024;

            if (regime >= 20)
            {
                dk = regime >= 30 ? 16 : 24;
                if (regime >= 34)
                {
                    dk = 8;
                }
            }
            key = sha.getDerivatoKey(bytes, oiv, dk, ref pc, regime >= 20 ? bytes.Length << 1 : bytes.Length, regime / 10);

            sha.Clear(true);
            sha = null;
            BytesBuilder.ToNull(bytes);
        }
Example #2
0
        private static void GetPasswordAndDecryptFile(FileInfo fi, out byte[] bt, DoublePasswordForm pwdForm1)
        {
            byte[] key;
            int    regime;

            using (var file = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                file.Position = 1;
                regime        = file.ReadByte();
            }

            GetKeyByPassword(pwdForm1, out key, regime);

/*
 #warning INSECURE
 * File.AppendAllText("unsecure.log", "key: " + BitConverter.ToString(key).Replace("-", "") + "\r\n");
 */
            pwdForm1.clearResultText();

            var sha = new SHA3(fi.Length);

            if (regime < 10)
            {
                sha.useOldDuplex = true;
            }

            var cbt = File.ReadAllBytes(fi.FullName);

            try
            {
                bt = sha.multiDecryptLZMA(cbt, key);
            }
            catch (Exception e)
            {
                MessageBox.Show("Расшифрование не удалось, возможно файл не является файлом программы rtbd. " + e.Message, "Расшифрование не удалось", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                bt = null;
                return;
            }
            finally
            {
                sha.Clear(true);
                BytesBuilder.ToNull(key);
                BytesBuilder.ToNull(cbt);
                cbt = null;
                key = null;
            }
        }
Example #3
0
        private void FileEncrypt(byte[] key, string FileName, int regime, int hashCount, bool LZMA)
        {
            GC.Collect();

            var bytes = File.ReadAllBytes(FileName);
            var sha   = new SHA3(bytes.LongLength);

            var crypted = sha.multiCryptLZMA(bytes, key, null, (byte)regime, LZMA, (byte)(LZMA ? 19 : 0), hashCount);

            BytesBuilder.ToNull(key);
            BytesBuilder.ToNull(bytes);
            sha.Clear(true);
            bytes = null;
            key   = null;

            File.WriteAllBytes(CryptFileName, crypted);
            BytesBuilder.ToNull(crypted);
            crypted = null;

            if (this.InvokeRequired)
            {
                try
                {
                    this.Invoke(new postFileEncryptFunc(this.postFileEncrypt));
                }
                catch
                {
                    postFileEncrypt();
                }
            }
            else
            {
                postFileEncrypt();
            }

            // MessageBox.Show("Файл зашифрован\r\nПроверьте возможность расшифровки\r\nУдалите нешифрованный файл, если это требуется", "Шифрование файла " + FileName, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }