zoukankan      html  css  js  c++  java
  • 加密解密文件

     1Decrypt 方法允许解密使用 Encrypt 方法加密的文件。Decrypt 方法只能解密使用当前用户帐户加密的文件。 
     2
     3Decrypt 方法要求独占访问被解密的文件,如果有其他进程正在使用该文件,此方法将引发异常。如果文件没有加密,则 Decrypt 将返回一个非零值,这表示成功。
     4
     5Encrypt 方法和 Decrypt 方法都使用计算机上安装的加密服务提供程序 (CSP) 和调用方法的进程的文件加密密钥。
     6
     7当前文件系统必须格式化为 NTFS,当前操作系统必须是 Microsoft Windows NT 或更高版本。 
     8
     9
    10using System;
    11using System.IO;
    12using System.Security.AccessControl;
    13
    14namespace FileSystemExample
    15{
    16    class FileExample
    17    {
    18        public static void Main()
    19        {
    20            try
    21            {
    22                string FileName = "test.xml";
    23
    24                Console.WriteLine("Enceypt " + FileName);
    25
    26                // Encrypt the file.
    27                AddEncryption(FileName);
    28
    29                Console.WriteLine("Decrypt " + FileName);
    30
    31                // Decrypt the file.
    32                RemoveEncryption(FileName);
    33
    34                Console.WriteLine("Done");
    35            }

    36            catch (Exception e)
    37            {
    38                Console.WriteLine(e);
    39            }

    40
    41            Console.ReadLine();
    42        }

    43
    44
    45        // Encrypt a file.
    46        public static void AddEncryption(string FileName)
    47        {
    48
    49            File.Encrypt(FileName);
    50
    51        }

    52
    53        // Decrypt a file.
    54        public static void RemoveEncryption(string FileName)
    55        {
    56            File.Decrypt(FileName);
    57        }

    58    }

    59}
  • 相关阅读:
    windows Git安装
    windows 下安装Python
    windows 下安装mongodb及其配置环境
    kafka服务安装-SuSE Linux Enterprise Server 11 SP3
    SUSE Linux 下redis 的坑
    windows 下安装nodejs及其配置环境
    redis服务器安装-SuSE Linux Enterprise Server 11 SP3
    svn服务器搭建-SuSE Linux Enterprise Server 11 SP3
    安装MySQL -- SuSE Linux Enterprise Server 11 SP3
    Git命令参考手册(文本版)
  • 原文地址:https://www.cnblogs.com/tiasys/p/605218.html
Copyright © 2011-2022 走看看