示例#1
0
        public bool InsertTemplate(string key, string value)
        {
            bool isSuccess = false;

            try
            {
                if (!Templates.ContainsKey(key))
                {
                    Templates.Add(key, TranString.EncodeBase64Unicode(value));
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
                if (isSuccess)
                {
                    SaveTemplate();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(isSuccess);
        }
示例#2
0
        private void buttonEncode_Click(object sender, EventArgs e)
        {
            try
            {
                switch (algorithm)
                {
                case Algorithm.Base64Unicode:
                    textBoxEncode.Text = TranString.EncodeBase64Unicode(textBoxDecode.Text);
                    break;

                case Algorithm.Base64:
                    textBoxEncode.Text = TranString.EncodeBase64(textBoxDecode.Text);
                    break;

                case Algorithm.UrlEncode:
                    textBoxEncode.Text = TranString.EncodeUrlEncode(textBoxDecode.Text);
                    break;

                case Algorithm.AES:
                    textBoxEncode.Text = TranString.EncodeAES(textBoxDecode.Text, textBoxKey.Text);
                    break;

                case Algorithm.Rijndael:
                    textBoxEncode.Text = TranString.EncodeRijndael(textBoxDecode.Text, textBoxRijndaelKey.Text, textBoxRijndaelVector.Text);
                    break;

                default:
                    throw new ArgumentOutOfRangeException($"algorithm : {algorithm}");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#3
0
        public void SaveUserData()
        {
            string        fullFilename = encryptedDataManagerContentsFullFilename;
            List <string> listName     = listData;

            lock (LockObj)
            {
                if (File.Exists(fullFilename))
                {
                    File.Delete(fullFilename);
                }


                if (LoginType.GOV == LoginType)
                {
                    dicData[new Tuple <Category, Key>(Category.Login, Key.LoginType)] = "GOV";
                }
                else
                {
                    dicData[new Tuple <Category, Key>(Category.Login, Key.LoginType)] = "Default";
                }

                var contents = new StringBuilder();

                foreach (string line in listName)
                {
                    try
                    {
                        if (line.StartsWith(@"#") || (line == null) || (line.Trim().Equals("")))
                        {
                            contents.Append(line + Environment.NewLine);
                        }
                        else
                        {
                            string[] lineValues = line.Split(new string[] { ":::" }, StringSplitOptions.None);
                            string   data       = string.Empty;
                            data = dicData[new Tuple <Category, Key>((Category)Enum.Parse(typeof(Category), lineValues[1]), (Key)Enum.Parse(typeof(Key), lineValues[2]))];
                            if (lineValues[0].ToString().ToUpper().Equals("Base64Unicode".ToUpper()))
                            {
                                data = TranString.EncodeBase64Unicode(data);
                            }
                            else if (lineValues[0].ToString().ToUpper().Equals("Base64Ascii".ToUpper()))
                            {
                                data = TranString.EncodeBase64(data);
                            }
                            contents.Append(lineValues[0] + ":::" + lineValues[1] + ":::" + lineValues[2] + ":::" + data + Environment.NewLine);
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }


                File.WriteAllText(fullFilename, TranString.EncodeAES(contents.ToString(), key));
            }
        }
示例#4
0
        private void WriteUpdateValue2File(List <string> listName, Dictionary <Tuple <Category, Key>, string> dicName, string filename)
        {
            lock (LockObj)
            {
                if (File.Exists(filename))
                {
                    File.Delete(filename);
                }

                using (StreamWriter file = new StreamWriter(filename))
                {
                    foreach (string line in listName)
                    {
                        try
                        {
                            if (line.StartsWith(@"#") || (line == null) || (line.Trim().Equals("")))
                            {
                                file.WriteLine(line);
                            }
                            else
                            {
                                string[] lineValues = line.Split(new string[] { ":::" }, StringSplitOptions.None);
                                string   data       = string.Empty;
                                data = dicData[new Tuple <Category, Key>((Category)Enum.Parse(typeof(Category), lineValues[1]), (Key)Enum.Parse(typeof(Key), lineValues[2]))];

                                if (lineValues[0].ToString().ToUpper().Equals("Base64Unicode".ToUpper()))
                                {
                                    data = TranString.EncodeBase64Unicode(data);
                                }
                                else if (lineValues[0].ToString().ToUpper().Equals("Base64Ascii".ToUpper()))
                                {
                                    data = TranString.EncodeBase64(data);
                                }

                                file.WriteLine(lineValues[0] + ":::" + lineValues[1] + ":::" + lineValues[2] + ":::" + data);
                            }
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                }
            }
        }
示例#5
0
        public async Task <string> Execute(string cmd, string cmdType, string cmdText, CsLib.RequestType type, string endPoint, string action, string accessKey, string secretKey, int timeoutSec = 0)
        {
            var json = new
            {
                cmd     = cmd,
                cmdType = cmdType,
                cmdText = TranString.EncodeBase64Unicode(cmdText)
            };

            string responseString = string.Empty;

            try
            {
                string        jsonCmd  = JsonConvert.SerializeObject(json);
                Task <string> response = new SoaCall().WebApiCall(
                    endPoint,
                    type,
                    action,
                    jsonCmd,
                    accessKey,
                    secretKey,
                    timeoutSec
                    );
                string temp = await response;
                if (temp.Length > 0)
                {
                    JToken jt = JToken.Parse(temp);
                    responseString = jt.ToString(Newtonsoft.Json.Formatting.Indented);
                }
                else
                {
                    responseString = "response is empty...";
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(responseString);
        }
示例#6
0
        private string GetRandomKey()
        {
            string key = string.Empty;

            if (!File.Exists(encryptionKeyFullFilename))
            {
                // create key file
                int randomKey = new Random().Next(1, 100000);
                key = TranString.EncodeBase64Unicode(randomKey.ToString());
                File.WriteAllText(encryptionKeyFullFilename, key, Encoding.Default);
                key = ("0123456789012345" + key);
                key = key.Substring(key.Length - 16);
            }
            else
            {
                // read key file
                key = File.ReadAllText(encryptionKeyFullFilename, Encoding.Default);
                //string InitFile = File.ReadAllText(dataManagerContentsInitFullFilename, Encoding.Default);
                key = ("0123456789012345" + key);
                key = key.Substring(key.Length - 16);
            }
            return(key);
        }