C # Talk about file manipulation NO1 (file encryption)

Source: Internet
Author: User

The first article describes some common operations for C # files

The most commonly used basic operations are: (1) File class files (2) folder class directory (3) file information class FileInfo (4) Folder information class DirectoryInfo

Stream operation: (1) file Stream class: FileStream (2) Stream write Class StreamWriter (3) stream read Class StreamReader (4) binary Stream write class BinaryWriter (5) binary stream read class BinaryReader

Static ClassFile

Operation of the File class

(1) Creation and opening of files

(2) Copying files

(3) deleting files

(4) Encryption and decryption of files

(5) file read

Basically is the above 5 kinds of operation, here is mainly to introduce the file encryption and decryption, the rest of the operation according to file corresponding method can be written.

There are a lot of ways to encrypt files, and here's a piece of encryption that I know about.

(1) First compress the files that need to be encrypted into a compressed package

(2) Then write a form on WinForm to implement an encrypted copy of the applet


(3) Start writing code in the Click event of the button

The file is read by the file stream first, and then the write operation is performed. Defines the 5K binary stream transfer rate. The following is the cryptographic operation, where the encryption is to change the contents of each byte[]5k byte transfer in the binary transfer process, and then perform the write operation. This will not open after the execution is complete.

<span style= "Font-family:microsoft yahei;font-size:18px;" >using (FileStream fsread=new FileStream (source,filemode. Open, FileAccess.                 Read) {using (FileStream fswrite=new FileStream (target,filemode.create, FileAccess.Write))                    {byte[] bytes = new byte[1024 * 5];                    int count = 0; while ((Count=fsread. Read (bytes,0,bytes.  Length)) {//>0) {//encrypt, in fact, change the contents of byte "", then perform the write operation for                        (int i = 0; i < count; i++) {Bytes[i] = (byte) (byte.                        Maxvalue-bytes[i]); }//Copy Fswrite.                    Write (bytes, 0, count); }}}</span> 

(4) Decryption operation, the target file on the form is written to the source file text box, and then the destination file to write another path, the equivalent of binary byte stream is transferred correctly. Then you can open it.

Directory

Operation of the folder class

(1) Create a folder

(2) Delete a folder

(3) Get folder

Instance ClassFileInfoDirectoryInfo

C # Talk about file manipulation NO1 (file encryption)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.