C#怎样对保存文件加密

 时间:2024-10-12 03:46:32

1、本文实例讲述了C#实现对文件进行加密解密的方法。

C#怎样对保存文件加密

3、解密代码如下:using System; using System.IO; using System.Security.Cryptography; public class Example19_10 { public static void Main() { // Create a new crypto provider TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider(); // open the file containing the key and IV FileStream fsKeyIn = File.OpenRead(@"c:\temp\encrypted.key"); // use a BinaryReader to read formatted data from the file BinaryReader br = new BinaryReader(fsKeyIn); // read data from the file and close it tdes.Key = br.ReadBytes(24); tdes.IV = br.ReadBytes(8); // Open the encrypted file FileStream fsIn = File.OpenRead(@"c:\\temp\\encrypted.txt"); // Create a cryptostream to decrypt from the filestream CryptoStream cs = new CryptoStream(fsIn, tdes.CreateDecryptor(), CryptoStreamMode.Read); // Create a StreamReader to format the input StreamReader sr = new StreamReader(cs); // And decrypt the data Console.WriteLine(sr.ReadToEnd()); sr.Close(); } }

C#怎样对保存文件加密
  • 安装固态盘出错
  • 武林外传怎么取消翅膀
  • 逆水寒虚拟内存怎么设置
  • Win7下查看DirectX版本
  • win11通过注册表禁用控制面板
  • 热门搜索
    皮肤发黄是什么原因 打k是什么意思 上位是什么意思 pce是什么意思 失眠多梦是什么原因 颠沛流离什么意思 什么是弱视 什么什么如什么 什么是债券 皮秒是什么