using CCS.Utility.Security;
using MES.Utility.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ursa.Controls;
using 常用工具集.Base;

namespace 常用工具集.ViewModel._05其他
{
    public class MD5DESViewModel : ViewModelBase
    {
        public string DESKey { get; set; } = "";
        public string DESSource { get; set; } = "";
        public string DESDest { get; set; } = "";
        public string MD5Source { get; set; } = "";
        public string MD5Dest { get; set; } = "";
        public DelegateCommand CalcMD5Cmd { get; set; }
        public DelegateCommand DESEncryptCmd { get; set; }
        public DelegateCommand DESDecryptCmd { get; set; }

        public MD5DESViewModel()
        {
            CalcMD5Cmd = new DelegateCommand(CalcMD5CmdFunc);

            DESEncryptCmd = new DelegateCommand(DESEncryptCmdFunc);
            DESDecryptCmd = new DelegateCommand(DESDecryptCmdFunc);
        }

        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="obj"></param>
        private void DESDecryptCmdFunc(object obj)
        {
            try
            {
                if (DESKey.IsNullOrEmpty())
                {
                    DESDest = DESHelper.DESDecrypt(DESSource);
                }
                else
                {
                    DESDest = DESHelper.DESDecrypt(DESSource, DESKey);
                }
            }
            catch (Exception ex)
            {
                DESDest = ex.Message;
            }
        }

        private void DESEncryptCmdFunc(object obj)
        {
            try
            {
                if (DESKey.IsNullOrEmpty())
                {
                    DESDest = DESHelper.DESEncrypt(DESSource);
                }
                else
                {
                    DESDest = DESHelper.DESEncrypt(DESSource, DESKey);
                }
            }
            catch (Exception ex)
            {
                DESDest = ex.Message;
            }
        }

        private void CalcMD5CmdFunc(object obj)
        {
            if (MD5Source.IsNullOrEmpty())
            {
                MessageBox.ShowAsync("请输入内容");
                return;
            }
            MD5Dest = MD5Source.MD5Encrypt();
        }
    }
}
