1 The decrypt method allows you to decrypt files encrypted using the encrypt method. The decrypt method can only decrypt files encrypted using the current user account.
2
3 The decrypt method requires exclusive access to the decrypted file. If another process is using the file, this method will cause an exception. If the file is not encrypted, decrypt returns a non-zero value, which indicates that the operation is successful.
4
5 Both the encrypt method and decrypt method use the file encryption key of the encrypted service provider (CSP) installed on the computer and the process that calls the method.
6
7 The current file system must be formatted as NTFS, and the current operating system must be Microsoft Windows NT or later.
8
9
10 Using System;
11 Using System. IO;
12 Using System. Security. accesscontrol;
13
14 Namespace 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 {
38Console. writeline (E );
39}
40
41 Console. Readline ();
42 }
43
44
45 // Encrypt a file.
46 Public Static Void Addencryption ( String Filename)
47 {
48
49File. Encrypt (filename );
50
51}
52
53 // Decrypt a file.
54 Public Static Void Removeencryption ( String Filename)
55 {
56File. decrypt (filename );
57}
58 }
59 }