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通过注册表禁用控制面板
  • 热门搜索
    玫瑰精油怎么用 孕妇怎么控制体重 生育险怎么交 白带褐色怎么回事 尘肺病怎么治疗 怎么打拼音 螨虫过敏症状怎么治 没有钱怎么创业 孕妇水肿怎么缓解 可可粉怎么吃