0

解密文件时出现错误。“路径不是合法的形式”

如果我手动指示 privateKeyLocation,例如 string privateKeyLocation = @"c:\privatekey.txt",它可以正常运行。

但我想自己使用打开文件对话框找到密钥文件。有人知道出了什么问题吗?提前致谢!

private void decryptFileButton_Click(object sender, EventArgs e)
        {
            string inputFileLocation = attachmentTextBox.Text;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.RestoreDirectory = true;
            string privateKeyLocation = new FileInfo(openFileDialog1.FileName).ToString();
            string privateKeyPassword = passphrase2TextBox.Text;
            string outputFile = @"c:\Original.txt";

            // decrypt and obtain the original file name
            // of the decrypted file
            string originalFileName =
                        pgp.DecryptFile(inputFileLocation,
                                    privateKeyLocation,
                                    privateKeyPassword,
                                    outputFile);
        }
4

1 回答 1

2

只是一个简单的 showdialog() 及其结果:

        private void decryptFileButton_Click(object sender, EventArgs e)
        {
            string inputFileLocation = attachmentTextBox.Text;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.RestoreDirectory = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string privateKeyLocation = new FileInfo(openFileDialog1.FileName).ToString();
                string privateKeyPassword = passphrase2TextBox.Text;
                string outputFile = @"c:\Original.txt";

                 decrypt and obtain the original file name
                 of the decrypted file
                string originalFileName =
                            pgp.DecryptFile(inputFileLocation,
                                        privateKeyLocation,
                                        privateKeyPassword,
                                        outputFile);
            }
        }
于 2013-10-30T01:46:39.607 回答