Esempio n. 1
0
        /// <summary>
        /// 数据处理 GetHostVersion
        /// </summary>
        /// <param name="_IPEndPoint"></param>
        private void PacketAction2(IPEndPoint _IPEndPoint)
        {
            if (!this.IncludeRemote(_IPEndPoint))
            {
                return;
            }
            else
            {
                this.UpdateRemote(_IPEndPoint);
            }
            Process p1     = Process.GetCurrentProcess();
            Object  packet = new{
                ActionId                    = 2, ActionName = "GetHostVersion", ErrorCode = 0, ErrorMessage = String.Empty,
                HostServiceVersion          = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(),
                HostServicePid              = p1.Id,
                HostServiceMemoryUsageBytes = p1.PrivateMemorySize64,
                HostServiceThreadsCount     = p1.Threads.Count,
#pragma warning disable IDE0037 // 使用推断的成员名称
                MachineName = p1.MachineName,
#pragma warning restore IDE0037 // 使用推断的成员名称
                MachineProcessorCount = Environment.ProcessorCount,
                //MachineMemoryTotalBytes=WMI.GetPhysicalMemorySize()
                //MachineMemoryAvailableBytes=PerformanceCounters.GetMachineMemoryAvailableBytes(),
            };

            p1.Dispose();
            String json = JsonConvert.SerializeObject(packet);

            Program.Logger.Log("UdpSocketServer", $"UdpPacketSent=>{_IPEndPoint.Address}:{_IPEndPoint.Port}=>{json}");
            this.AsyncNetUdpServer.SendAsync(AesEncrypt.Encrypt(Program.AppSettings.ControlKey, json), _IPEndPoint);
        }
Esempio n. 2
0
        private async Task ProcessDeliveriesAsync(ChannelReader <Letter> channelReader)
        {
            while (await channelReader.WaitToReadAsync().ConfigureAwait(false))
            {
                while (channelReader.TryRead(out var letter))
                {
                    if (letter == null)
                    {
                        continue;
                    }

                    if (Compress)
                    {
                        letter.Body = await Gzip.CompressAsync(letter.Body).ConfigureAwait(false);

                        letter.LetterMetadata.Compressed = Compress;
                    }

                    if (Encrypt && (_hashKey != null || _hashKey.Length == 0))
                    {
                        letter.Body = AesEncrypt.Encrypt(letter.Body, _hashKey);
                        letter.LetterMetadata.Encrypted = Encrypt;
                    }

                    _logger.LogDebug(LogMessages.AutoPublisher.LetterPublished, letter.LetterId, letter.LetterMetadata?.Id);

                    await Publisher
                    .PublishAsync(letter, CreatePublishReceipts, _withHeaders)
                    .ConfigureAwait(false);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 服务端收到数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AsyncNetUdpServer_UdpPacketArrived(object sender, UdpPacketArrivedEventArgs e)
        {
            String dataJson = AesEncrypt.Decrypt(Program.AppSettings.ControlKey, e.PacketData).TrimEnd('\0');

            Program.Logger.Log("UdpSocketServer", $"UdpPacketArrived=>{e.RemoteEndPoint.Address}:{e.RemoteEndPoint.Port}=>{dataJson}");
            if (String.IsNullOrWhiteSpace(dataJson) || dataJson.IndexOf("ActionId") < 0 || dataJson.IndexOf("ActionName") < 0)
            {
                this.AsyncNetUdpServer.Post($"UnknownDataPacket,Logged\"{e.RemoteEndPoint.Address}:{e.RemoteEndPoint.Port}\"".GetBytes_Utf8(), e.RemoteEndPoint);
                return;
            }
            Entity.UdpSocketPacketRecive packet = null;
            try { packet = JsonConvert.DeserializeObject <Entity.UdpSocketPacketRecive>(dataJson); } catch {}
            if (packet == null)
            {
                this.AsyncNetUdpServer.Post($"UnknownDataPacket,Logged\"{e.RemoteEndPoint.Address}:{e.RemoteEndPoint.Port}\"".GetBytes_Utf8(), e.RemoteEndPoint);
                return;
            }
            switch (packet.ActionId)
            {
            case 1: this.PacketAction1(e.RemoteEndPoint); break;

            case 2: this.PacketAction2(e.RemoteEndPoint); break;

            case 1001: this.PacketAction1001(e.RemoteEndPoint); break;

            case 1002: this.PacketAction1002(e.RemoteEndPoint); break;

            case 1003: this.PacketAction1003(e.RemoteEndPoint, packet); break;

            case 1004: this.PacketAction1004(e.RemoteEndPoint); break;

            case 1005: this.PacketAction1005(e.RemoteEndPoint, packet); break;
            }
        }
Esempio n. 4
0
        public static string EncryptText(string text, string passwordPhrase)
        {
            var aesEncrypted = AesEncrypt.EncryptText(text, passwordPhrase);
            var desEncrypted = DesEncrypt.EncryptString(aesEncrypted, passwordPhrase);

            return(desEncrypted);
        }
Esempio n. 5
0
        // Returns Success
        public bool Decrypt(Letter letter)
        {
            if (!letter.LetterMetadata.Encrypted || (_hashKey == null && _hashKey.Length == 0))
            {
                return(false);
            }                 // Don't decrypt without it being encrypted.

            try
            {
                letter.Body = AesEncrypt.Decrypt(letter.Body, _hashKey);
                letter.LetterMetadata.Encrypted = false;

                if (letter.LetterMetadata.CustomFields.ContainsKey(Utils.Constants.HeaderForEncrypt))
                {
                    letter.LetterMetadata.CustomFields.Remove(Utils.Constants.HeaderForEncrypt);
                }

                if (letter.LetterMetadata.CustomFields.ContainsKey(Utils.Constants.HeaderForEncryptDate))
                {
                    letter.LetterMetadata.CustomFields.Remove(Utils.Constants.HeaderForEncryptDate);
                }
            }
            catch { return(false); }

            return(true);
        }
Esempio n. 6
0
        public async Task DecomcryptAsync(Letter letter)
        {
            var decryptFailed = false;

            if (letter.LetterMetadata.Encrypted && (_hashKey?.Length > 0))
            {
                try
                {
                    letter.Body = AesEncrypt.Decrypt(letter.Body, _hashKey);
                    letter.LetterMetadata.Encrypted = false;
                }
                catch { decryptFailed = true; }
            }

            if (!decryptFailed && letter.LetterMetadata.Compressed)
            {
                try
                {
                    letter.Body = await Gzip.DecompressAsync(letter.Body).ConfigureAwait(false);

                    letter.LetterMetadata.Compressed = false;
                }
                catch { }
            }
        }
Esempio n. 7
0
        private async Task ProcessDeliveriesAsync(ChannelReader <Letter> channelReader)
        {
            while (await channelReader.WaitToReadAsync().ConfigureAwait(false))
            {
                while (channelReader.TryRead(out var letter))
                {
                    if (letter == null)
                    {
                        continue;
                    }

                    if (_compress)
                    {
                        letter.Body = await Gzip.CompressAsync(letter.Body).ConfigureAwait(false);

                        letter.LetterMetadata.Compressed = _compress;
                        letter.LetterMetadata.CustomFields[Utils.Constants.HeaderForEncrypt] = Utils.Constants.HeaderValueForGzipCompress;
                    }

                    if (_encrypt)
                    {
                        letter.Body = AesEncrypt.Encrypt(letter.Body, _hashKey);
                        letter.LetterMetadata.Encrypted = _encrypt;
                        letter.LetterMetadata.CustomFields[Utils.Constants.HeaderForEncrypt] = Utils.Constants.HeaderValueForArgonAesEncrypt;
                    }

                    _logger.LogDebug(LogMessages.AutoPublisher.LetterPublished, letter.LetterId, letter.LetterMetadata?.Id);

                    await PublishAsync(letter, _createPublishReceipts, _withHeaders)
                    .ConfigureAwait(false);
                }
            }
        }
Esempio n. 8
0
        public async Task ComcryptDecomcryptTest()
        {
            var message = new Message {
                StringMessage = $"Sensitive ReceivedLetter 0", MessageId = 0
            };
            var data = JsonSerializer.SerializeToUtf8Bytes(message);

            var hashKey = await ArgonHash
                          .GetHashKeyAsync(Passphrase, Salt, HouseofCat.Encryption.Constants.Aes256.KeySize)
                          .ConfigureAwait(false);

            _output.WriteLine(Encoding.UTF8.GetString(hashKey));
            _output.WriteLine($"HashKey: {Encoding.UTF8.GetString(hashKey)}");

            // Comcrypt
            var payload = await Gzip.CompressAsync(data);

            var encryptedPayload = AesEncrypt.Aes256Encrypt(payload, hashKey);

            // Decomcrypt
            var decryptedData = AesEncrypt.Aes256Decrypt(encryptedPayload, hashKey);

            Assert.NotNull(decryptedData);

            var decompressed = await Gzip.DecompressAsync(decryptedData);

            JsonSerializer.SerializeToUtf8Bytes(decompressed);
            _output.WriteLine($"Data: {Encoding.UTF8.GetString(data)}");
            _output.WriteLine($"Decrypted: {Encoding.UTF8.GetString(decryptedData)}");

            Assert.Equal(data, decompressed);
        }
        /// <summary>
        /// ログインを試みる
        /// </summary>
        /// <param name="driver"></param>
        /// <returns></returns>
        private bool TryLogin(IWebDriver driver)
        {
            bool ret = false;

            log.Debug("ログイン中");
            Message = "ログイン中";
            try
            {
                log.Debug(String.Format("処理中:{0}", SiteConfig.XPATH_FORM_ADDRESS));
                driver.FindElement(By.XPath(SiteConfig.XPATH_FORM_ADDRESS)).SendKeys(_loginInfo.LoginAddress);
                log.Debug(String.Format("処理中:{0}", SiteConfig.XPATH_PASS));
                driver.FindElement(By.XPath(SiteConfig.XPATH_PASS)).SendKeys(AesEncrypt.DecryptFromBase64(_loginInfo.LoginPass, AesKeyConf.key, AesKeyConf.iv));
                log.Debug(String.Format("処理中:{0}", SiteConfig.XPATH_LOGINBTN));
                driver.FindElement(By.XPath(SiteConfig.XPATH_LOGINBTN)).Click();

                // ログイン失敗
                if (driver.Url.Equals(String.Format("{0}login", SiteConfig.BASE_URL)))
                {
                    // ret = false;
                }
                else
                {
                    ret = true;
                }
            }
            catch (NoSuchElementException)
            {
                // ログイン不要
                ret = true;
            }
            return(ret);
        }
Esempio n. 10
0
    /// <summary>
    /// aes加混淆解密接口
    /// </summary>
    static public byte[] ExecuteDecrypt(byte[] buffer, string key)
    {
        //这里后续附加混淆规则
        int bufferLen = buffer.Length;

        if (bufferLen > MAX_ENCRYPT_LEN)
        {
            //规定 ECBMode:(明文长度/16 + 1) * 16 = 密文长度
            int    decryLen    = (MAX_ENCRYPT_LEN / BLOCK_SIZE + 1) * BLOCK_SIZE;
            byte[] decryBuffer = new byte[decryLen];
            Array.Copy(buffer, decryBuffer, decryLen);
            byte[] beDecryBuffer = AesEncrypt.Decrypt(decryBuffer, key);
            int    retLen        = bufferLen - decryLen + beDecryBuffer.Length;
            byte[] retBuffer     = new byte[retLen];
            beDecryBuffer.CopyTo(retBuffer, 0);
            Array.Copy(buffer, decryLen, retBuffer, beDecryBuffer.Length, retBuffer.Length - beDecryBuffer.Length);

            for (int i = beDecryBuffer.Length, j = 0; i < retLen; i += CONFUSE_OFFSET)
            {
                retBuffer[i] -= beDecryBuffer[j];
                j            += 2;
                if (j >= beDecryBuffer.Length)
                {
                    j = 0;
                }
            }

            return(retBuffer);
        }
        else
        {
            return(AesEncrypt.Decrypt(buffer, key));
        }
    }
Esempio n. 11
0
    /// <summary>
    /// aes加混淆加密接口
    /// </summary>
    static public byte[] ExecuteEncrypt(byte[] buffer, string key)
    {
        //这里后续附加混淆规则
        int bufferLen = buffer.Length;

        if (bufferLen > MAX_ENCRYPT_LEN)
        {
            //规定 ECBMode:(明文长度/16 + 1) * 16 = 密文长度
            int    retLen      = bufferLen - MAX_ENCRYPT_LEN + (MAX_ENCRYPT_LEN / BLOCK_SIZE + 1) * BLOCK_SIZE;
            byte[] encryBuffer = new byte[MAX_ENCRYPT_LEN];
            byte[] retBuffer   = new byte[retLen];
            Array.Copy(buffer, encryBuffer, MAX_ENCRYPT_LEN);
            byte[] beEncryBuffer = AesEncrypt.Encrypt(encryBuffer, key);
            beEncryBuffer.CopyTo(retBuffer, 0);
            Array.Copy(buffer, MAX_ENCRYPT_LEN, retBuffer, beEncryBuffer.Length, bufferLen - MAX_ENCRYPT_LEN);

            for (int i = beEncryBuffer.Length, j = 0; i < retBuffer.Length; i += CONFUSE_OFFSET)
            {
                retBuffer[i] += buffer[j];
                j            += 2;
                if (j >= MAX_ENCRYPT_LEN)
                {
                    j = 0;
                }
            }

            return(retBuffer);
        }
        else
        {
            return(AesEncrypt.Encrypt(buffer, key));
        }
    }
Esempio n. 12
0
        public void TestW()
        {
            Base64 uy = new Base64();

            //var f= uy.Base64EnCode("12345678张三李四");//\u001f 这个表示的是一个编码的对应值,其实也就是一个数字


            var qs = uy.Base64EnCode("12345678张三李四");

            var fs = uy.Base64EnCode("abcdsdfdsdfdsdfdsssssssf");

            //输入一个字符串,经过64编码后有24个字符,获取字节数只有16个
            //tiihtNczf5v6AKRyjwEUhQ==

            IEncrypted encrypted = new AesEncrypt(fs, qs);

            var q = encrypted.CryptStr(Newtonsoft.Json.JsonConvert.SerializeObject(new
            {
                Name = "张三",
                Age  = 14
            }));


            var b = encrypted.DecryptStr(q);
        }
Esempio n. 13
0
        public static ResponseView <TokenModel> TryGetTokenModel(string source)
        {
            ResponseView <TokenModel> response = null;

            if (string.IsNullOrWhiteSpace(source))
            {
                response = new ResponseView <TokenModel>("无效用户", false, null);
                return(response);
            }
            try
            {
                IEncrypted encrypted = new AesEncrypt(DEFAULTKEY, DEFAULTIV);

                var deEnctrypedStr = encrypted.CryptStr(source);

                var model = JsonPase.Deserialize <TokenModel>(deEnctrypedStr);

                response = new ResponseView <TokenModel>("", true, model);
            }
            catch (Exception ex)
            {
                response = new ResponseView <TokenModel>("非法用户", false, null);
            }
            return(response);
        }
Esempio n. 14
0
        public string ToToken()
        {
            IEncrypted encrypted = new AesEncrypt(DEFAULTKEY, DEFAULTIV);

            var str = JsonPase.Serialize(this);

            var data = encrypted.CryptStr(str);

            return(data);
        }
Esempio n. 15
0
        public static string DecryptText(string text, string passwordPhrase)
        {
            var desDecrypted = DesEncrypt.DecryptString(text, passwordPhrase);

            //Remove pad bytes...
            desDecrypted = desDecrypted.Replace("\0", string.Empty);

            var aesDecrypted = AesEncrypt.DecryptText(desDecrypted, passwordPhrase);

            return(aesDecrypted);
        }
Esempio n. 16
0
        public override void Flush(byte type)
        {
            Writer.BaseStream.Position = 6;
            Writer.Write((byte)0x0b);
            Writer.Write(RtmfpUtils.TimeNow());
            Writer.Write(type);
            Writer.Write((short)(Writer.BaseStream.GetAvaliableByteCounts() - 2));
            var encoder = AesEncrypt.Next(AESEngine.AESType.SYMMETRIC);

            RtmfpUtils.EncodeAndPack(encoder, Writer, 0);
            EnqueueForOutbound(OutputBuffer);
            Writer.Clear(11);
        }
Esempio n. 17
0
        public bool Decrypt(Letter letter)
        {
            if (letter.LetterMetadata.Encrypted && (_hashKey?.Length > 0))
            {
                try
                {
                    letter.Body = AesEncrypt.Decrypt(letter.Body, _hashKey);
                    letter.LetterMetadata.Encrypted = false;
                }
                catch { }
            }

            return(!letter.LetterMetadata.Encrypted);
        }
Esempio n. 18
0
        public async Task DecomcryptDataAsync(bool decrypt = false, bool decompress = false)
        {
            if (!_decrypted && decrypt && _hashKey.Length > 0)
            {
                Data       = AesEncrypt.Decrypt(Data, _hashKey);
                _decrypted = true;
            }

            if (!_decompressed && decompress)
            {
                Data = await Gzip
                       .DecompressAsync(Data)
                       .ConfigureAwait(false);

                _decompressed = true;
            }
        }
Esempio n. 19
0
        /// <summary>
        /// 数据处理 StopAllUnits
        /// </summary>
        /// <param name="_IPEndPoint"></param>
        private void PacketAction1004(IPEndPoint _IPEndPoint)
        {
            if (!this.IncludeRemote(_IPEndPoint))
            {
                return;
            }
            else
            {
                this.UpdateRemote(_IPEndPoint);
            }
            UnitControl.StopAllUnits();
            Object packet = new{ ActionId = 1004, ActionName = "StopAllUnits", ErrorCode = 0, ErrorMessage = String.Empty };
            String json   = JsonConvert.SerializeObject(packet);

            Program.Logger.Log("UdpSocketServer", $"UdpPacketSent=>{_IPEndPoint.Address}:{_IPEndPoint.Port}=>{json}");
            this.AsyncNetUdpServer.SendAsync(AesEncrypt.Encrypt(Program.AppSettings.ControlKey, json), _IPEndPoint);
        }
Esempio n. 20
0
        public bool Encrypt(Letter letter)
        {
            if (letter.LetterMetadata.Encrypted || (_hashKey == null && _hashKey.Length == 0))
            {
                return(false);
            }                 // Don't double encrypt.

            try
            {
                letter.Body = AesEncrypt.Encrypt(letter.Body, _hashKey);
                letter.LetterMetadata.Encrypted = true;
                letter.LetterMetadata.CustomFields[Utils.Constants.HeaderForEncrypt]     = Utils.Constants.HeaderValueForArgonAesEncrypt;
                letter.LetterMetadata.CustomFields[Utils.Constants.HeaderForEncryptDate] = Time.GetDateTimeUtcNow();
            }
            catch { return(false); }

            return(true);
        }
Esempio n. 21
0
        /// <summary>
        /// 数据处理 Hello
        /// </summary>
        /// <param name="_IPEndPoint"></param>
        private void PacketAction1(IPEndPoint _IPEndPoint)
        {
            if (!this.IncludeRemote(_IPEndPoint))
            {
                this.Remotes.Add(new Entity.UdpSocketRemote {
                    IPEndPoint = _IPEndPoint, LastUpdateTime = DateTimeOffset.Now.ToUnixTimeSeconds()
                });
            }
            else
            {
                this.UpdateRemote(_IPEndPoint);
            }
            Object packet = new{ ActionId = 1, ActionName = "Hello", ErrorCode = 0, ErrorMessage = String.Empty, Message = $"Hello,{_IPEndPoint.Address}:{_IPEndPoint.Port}" };
            String json   = JsonConvert.SerializeObject(packet);

            Program.Logger.Log("UdpSocketServer", $"UdpPacketSent=>{_IPEndPoint.Address}:{_IPEndPoint.Port}=>{json}");
            this.AsyncNetUdpServer.SendAsync(AesEncrypt.Encrypt(Program.AppSettings.ControlKey, json), _IPEndPoint);
        }
Esempio n. 22
0
        public bool Encrypt(Letter letter)
        {
            if (letter.LetterMetadata.Encrypted || (_hashKey == null && _hashKey.Length == 0))
            {
                return(false);
            }                 // Don't double encrypt.

            try
            {
                letter.Body = AesEncrypt.Aes256Encrypt(letter.Body, _hashKey);
                letter.LetterMetadata.Encrypted = true;
                letter.LetterMetadata.CustomFields[Constants.HeaderForEncrypted]   = true;
                letter.LetterMetadata.CustomFields[Constants.HeaderForEncryption]  = Constants.HeaderValueForArgonAesEncrypt;
                letter.LetterMetadata.CustomFields[Constants.HeaderForEncryptDate] = Time.GetDateTimeNow(Time.Formats.CatRFC3339);
            }
            catch { return(false); }

            return(true);
        }
Esempio n. 23
0
        public async Task EncryptDecryptTest()
        {
            var data = new byte[] { 0xFF, 0x00, 0xAA, 0xFF, 0x00, 0x00, 0xFF, 0xAA, 0x00, 0xFF, 0x00, 0xFF };

            var hashKey = await ArgonHash
                          .GetHashKeyAsync(Passphrase, Salt, 32)
                          .ConfigureAwait(false);

            _output.WriteLine(Encoding.UTF8.GetString(hashKey));
            _output.WriteLine($"HashKey: {Encoding.UTF8.GetString(hashKey)}");

            var encryptedData = AesEncrypt.Aes256Encrypt(data, hashKey);

            _output.WriteLine($"Encrypted: {Encoding.UTF8.GetString(encryptedData)}");

            var decryptedData = AesEncrypt.Aes256Decrypt(encryptedData, hashKey);

            _output.WriteLine($"Data: {Encoding.UTF8.GetString(data)}");
            _output.WriteLine($"Decrypted: {Encoding.UTF8.GetString(decryptedData)}");

            Assert.Equal(data, decryptedData);
        }
Esempio n. 24
0
        /// <summary>
        /// 数据处理 StopUnit
        /// </summary>
        /// <param name="_IPEndPoint"></param>
        /// <param name="_UdpSocketPacketRecive"></param>
        private void PacketAction1005(IPEndPoint _IPEndPoint, Entity.UdpSocketPacketRecive _UdpSocketPacketRecive)
        {
            if (!this.IncludeRemote(_IPEndPoint))
            {
                return;
            }
            else
            {
                this.UpdateRemote(_IPEndPoint);
            }
            Object packet = new{ ActionId = 1005, ActionName = "StopUnit", ErrorCode = 0, ErrorMessage = String.Empty };

            if (String.IsNullOrWhiteSpace(_UdpSocketPacketRecive.UnitName))
            {
                packet = new{ ActionId = 1005, ActionName = "StopUnit", ErrorCode = 101, ErrorMessage = "单元名称无效" };
            }                                                                                                                                                   //TODO 优化
            UnitControl.StopUnit(_UdpSocketPacketRecive.UnitName);
            String json = JsonConvert.SerializeObject(packet);

            Program.Logger.Log("UdpSocketServer", $"UdpPacketSent=>{_IPEndPoint.Address}:{_IPEndPoint.Port}=>{json}");
            this.AsyncNetUdpServer.SendAsync(AesEncrypt.Encrypt(Program.AppSettings.ControlKey, json), _IPEndPoint);
        }
Esempio n. 25
0
        /// <summary>
        /// 数据处理 FetchUnits
        /// </summary>
        /// <param name="_IPEndPoint"></param>
        private void PacketAction1001(IPEndPoint _IPEndPoint)
        {
            if (!this.IncludeRemote(_IPEndPoint))
            {
                return;
            }
            else
            {
                this.UpdateRemote(_IPEndPoint);
            }
            Dictionary <String, Object> d1 = new Dictionary <String, Object>();

#pragma warning disable IDE0037 // 使用推断的成员名称
            foreach (KeyValuePair <String, Entity.Unit> kvp in Program.Units)
            {
                d1[kvp.Key] = new { State = kvp.Value.State, UnitSettings = kvp.Value.UnitSettings };
            }
#pragma warning restore IDE0037 // 使用推断的成员名称
            Object packet = new{ ActionId = 1001, ActionName = "FetchUnits", ErrorCode = 0, ErrorMessage = String.Empty, Units = d1 };
            String json   = JsonConvert.SerializeObject(packet);
            Program.Logger.Log("UdpSocketServer", $"UdpPacketSent=>{_IPEndPoint.Address}:{_IPEndPoint.Port}=>{json}");
            this.AsyncNetUdpServer.SendAsync(AesEncrypt.Encrypt(Program.AppSettings.ControlKey, json), _IPEndPoint);
        }
        public void ExecuteConfigure()
        {
            // データ読み出し
            var configTuple = LoadConfig();

            CurrentLogConfig = configTuple.Item1;
            CurrentLoginInfo = configTuple.Item2;
            try
            {
                //CurrentAesPass = AesEncrypt.DecryptFromBase64(configTuple.Item2.LoginPass, AesKeyConf.key, AesKeyConf.iv);
                CurrentAesPass = SecureStringConverter.PlainToSecure(AesEncrypt.DecryptFromBase64(configTuple.Item2.LoginPass, AesKeyConf.key, AesKeyConf.iv));
            }
            catch
            {
                CurrentAesPass = new SecureString();
            }

            DType      = DialogType.Configure;
            DialogView = new UserSettingsDialog()
            {
                DataContext = this
            };
            IsDialogOpen = true;
        }
Esempio n. 27
0
        public async Task CreateLetterFromDataAsync()
        {
            if (Letter == null)
            {
                Letter = JsonSerializer.Deserialize <Letter>(Data);
            }

            if (!_decrypted && Letter.LetterMetadata.Encrypted && _hashKey.Length > 0)
            {
                Letter.Body = AesEncrypt.Decrypt(Letter.Body, _hashKey);
                Letter.LetterMetadata.Encrypted = false;
                _decrypted = true;
            }

            if (!_decompressed && Letter.LetterMetadata.Compressed)
            {
                Letter.Body = await Gzip
                              .DecompressAsync(Letter.Body)
                              .ConfigureAwait(false);

                Letter.LetterMetadata.Compressed = false;
                _decompressed = true;
            }
        }
        public async void AcceptDialog()
        {
            // ダイアログ種別で分岐
            switch (DType)
            {
            case DialogType.Configure:
                // 設定を保存
                XmlConverter.Serialize(CurrentLogConfig, String.Format(@"{0}\LogConfig.xml", SiteConfig.BASE_DIR));
                if (CurrentLoginInfo is null)
                {
                    CurrentLoginInfo = new LoginInfo();
                }
                CurrentLoginInfo.LoginPass = AesEncrypt.EncryptToBase64(SecureStringConverter.SecureToPlain(CurrentAesPass), AesKeyConf.key, AesKeyConf.iv);
                XmlConverter.Serialize(CurrentLoginInfo, String.Format(@"{0}\LoginInfo.xml", SiteConfig.BASE_DIR));

                // ダイアログを閉じる
                IsDialogOpen = false;
                DialogView   = null;
                break;

            case DialogType.HotelUpdate:
                // Viewの型で更に分岐
                switch (DialogView)
                {
                case MaterialDialogOkCancel okCancelDialog:
                    // ダイアログを閉じる
                    IsDialogOpen = false;
                    DialogView   = null;

                    // 次のダイアログを表示する
                    Message    = "処理中...";
                    DialogView = new MaterialDialogProcessing()
                    {
                        DataContext = this
                    };
                    IsDialogOpen = true;

                    // 処理モデル定義
                    var model = new HotelUpdate();
                    await Task.Run(() =>
                    {
                        // 処理実行
                        model.Execute();
                    });

                    // 処理成功
                    if (model.Result)
                    {
                        // ダイアログを閉じる
                        IsDialogOpen = false;
                        DialogView   = null;

                        // 次のダイアログを表示する
                        Message    = "完了しました\r\n";
                        DialogView = new MaterialDialogOk()
                        {
                            DataContext = this
                        };
                        IsDialogOpen = true;
                    }
                    break;

                case MaterialDialogOk okDialog:
                    // ダイアログを閉じる
                    IsDialogOpen = false;
                    DialogView   = null;
                    break;
                }
                break;

            case DialogType.License:
                // ダイアログを閉じる
                IsDialogOpen = false;
                DialogView   = null;
                break;
            }
        }
Esempio n. 29
0
 public void EncryptDecrypt1024()
 {
     var decryptedData = AesEncrypt.Decrypt(AesEncrypt.Encrypt(Payload3, HashKey), HashKey);
 }
Esempio n. 30
0
 public void EncryptDecrypt512()
 {
     var decryptedData = AesEncrypt.Decrypt(AesEncrypt.Encrypt(Payload2, HashKey), HashKey);
 }