Пример #1
0
        private void Btnファイルに保存_Click(object sender, EventArgs e)
        {
            try
            {
                string rawKey = this.RawKey.Text;

                if (rawKey == "")
                {
                    throw new Exception("[鍵またはパスフレーズ]を入力して下さい。");
                }
                string rawKeyCheckSum = Tools.GetCheckSum(rawKey);

                string file = SaveLoadDialogs.SaveFile(
                    "保存先のファイルを選択してください",
                    "鍵:rawkey",
                    Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                    "CPortFwd_KeyOrPass_" + Tools.GetCompactStamp(DateTime.Now) + ".rawkey"
                    );

                if (file != null)
                {
                    List <string> lines = new List <string>();

                    lines.Add("<?xml version=\"1.0\" encoding=\"Shift_JIS\"?>");
                    lines.Add("<Root>");
                    lines.Add("<CPortFwd>");
                    lines.Add("<RawKey>");
                    lines.Add(rawKey);
                    lines.Add("</RawKey>");
                    lines.Add("<RawKey-SUM>");
                    lines.Add(rawKeyCheckSum);
                    lines.Add("</RawKey-SUM>");
                    lines.Add("</CPortFwd>");
                    lines.Add("</Root>");

                    File.WriteAllLines(file, lines, Encoding.GetEncoding(932));

                    MessageBox.Show(
                        "[鍵またはパスフレーズ]を保存しました。",
                        "確認",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information
                        );
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    "鍵ファイルの保存に失敗しました。\n" + ex,
                    "エラー",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
            }
        }
Пример #2
0
        private void Btnファイルから読み込み_Click(object sender, EventArgs e)
        {
            try
            {
                string file = SaveLoadDialogs.LoadFile(
                    "開くファイルを選択してください",
                    "鍵:rawkey",
                    Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                    "*.rawkey"
                    );

                if (file != null)
                {
                    XNode  root                = XNode.Load(file);
                    string rawKey              = root.GetChild("CPortFwd").GetChild("RawKey").Text;
                    string rawKeyCheckSum      = Tools.GetCheckSum(rawKey);
                    string read_rawKeyCheckSum = root.GetChild("CPortFwd").GetChild("RawKey-SUM").Text;

                    if (read_rawKeyCheckSum != rawKeyCheckSum)
                    {
                        throw new Exception("【チェックサムが一致しません】");
                    }
                    rawKey           = Tools.PassphraseFltr(rawKey);
                    this.RawKey.Text = rawKey;

                    MessageBox.Show(
                        "[鍵またはパスフレーズ]を読み込みました。",
                        "確認",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information
                        );
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    "鍵ファイルの読み込みに失敗しました。\n" + ex,
                    "エラー",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
            }
        }