前提 1.导入老师所给文件:3des.cs,加入命名空间threeDes,便于其他文件引用。 2.软件:vs code
过程
1.加密文件
加密代码如下:
- using System;
- using threeDes;
- namespace ConsoleApplication1
- {
- class encode
- {
- static void Main(string[] args)
- {
- //秘钥
- string sKey = "qJzGEh6hESZDVJeCnFPGuxzaiB7NLQM5";
- //调用IV有值的构造函数
- TripleDES_ a =new TripleDES_(sKey);
- Console.WriteLine("请输入待加密文件名:(绝对路径)");
- string input = Console.ReadLine();
- Console.WriteLine("请输入存储文件名:(绝对路径)");
- string output = Console.ReadLine();
- a.Encrypt(input, output);
- Console.WriteLine("执行成功。");
- }
- }
- }
复制代码 运行界面:
E盘里:
文件内容:(此处加密文件为乱码,找了很多方法没有解决这个问题)
2.解密文件
解密文件代码如下:
- using System;
- using threeDes;
- namespace ConsoleApplication2
- {
- class decode
- {
- static void Main(string[] args)
- {
- //秘钥
- string sKey = "qJzGEh6hESZDVJeCnFPGuxzaiB7NLQM5";
- //调用IV有值的构造函数
- TripleDES_ a =new TripleDES_(sKey);
- Console.WriteLine("请输入待解密文件名:(绝对路径)");
- string input = Console.ReadLine();
- Console.WriteLine("请输入存储文件名:(绝对路径)");
- string output = Console.ReadLine();
- a.Decrypt(input, output);
- Console.WriteLine("执行成功。");
- }
- }
- }
复制代码 运行界面:
E盘里:
文件内容:(为了方便,待解密文件取上述得到的加密文件)
总结
1.通过代码导出的文件内容为乱码,初步分析问题为txt解析中文用的是gb2312,与VS code的不一致,但没有找到解决办法。
2.因为要执行加密程序和解密文件,而两个都是用main方法写成,因此在运行其中一个时,要注释掉另一个文件内容。否则会提示:
3.加密和解密代码虽然可以成功执行,但实际上还是有关于输入与输出语句的警告:
4.在调试代码时,出现了这样的弹窗错误:
${workspaceFolder}/bin/Debug/insert-target-framework-here/insert-project-name-here.dll不存在
需要在launch.json中吧“Program”改为如下内容即可:
|