C # Cryptographic Gadget code implementation

Source: Internet
Author: User

The key points are as follows:

1. Use of OpenFileDialog controls
What if you chose a local file by clicking the Select button?
In particular, it is divided into the following steps:

A, create a new WinForm form and draw the appropriate controls.

B, find the OpenFileDialog in the toolbox, and drag to the Select File button, and this will appear as follows:

At this point, the OpenFileDialog will appear below the interface, not the interface, so that you can open a local file by clicking the Select File button.

The following lines of code need to be added to the click function of the Select File button:

DialogResult Diaresult = This.openFile.ShowDialog (), if (Diaresult = = DialogResult.OK) {        //internal can get information such as file name}

So what if we get the file name and path information under the open path?

These properties can be used to implement the following:

A, the FileName property of the OpenFileDialog control to get the path information, at which time the path information contains the file name and filename extension.

For example: E:\Work\Vs\TestEncryption\ encryption processing \ To encrypt \ Dead shoreline.

b, what if you just want to get the "dead shoreline" file name?

Path.getfilenamewithoutextension (PathName) can realize this function, and at this time without file extension of the name AO, the incoming parameter pathName is a path information in a.

So how do you get the file size and extension name after selecting the appropriate file? The following code can be implemented:

FileInfo fi = new FileInfo (pathName); filetype = fi. extension;//file extension filesize = fi. length;//the number of bytes of file information

There are three ways to set the initial open path of the OpenFileDialog control:
1, the following two lines of code the effect is the same (this is two kinds):

Openfilesave.initialdirectory = "e:\\work\\vs\\testencryption\\ encryption processing \ \ Save File"; openfilesave.initialdirectory = @ "E:\\ work\\vs\\testencryption\\ encryption processing \ \ Save File ";

Another way to do this is by right-clicking the property on the OpenFileDialog control.

One of the properties is: InitialDirectory, fill in the following: E:\Work\Vs\TestEncryption\ encryption processing \ To encrypt \ Save the file, the effect is the same as the above two lines of code.

C, a few of the functions used are:

        <summary>///        read the file information under Execution Path////</summary>//        <param name= "filename" > The specified path </ param>//        <param name= "Start" > Start position, generally set to zero </param>//        <param name= "Length" > Length of File information </param>        //<returns></returns> public static byte[] ReadFile (string filename, int start, int length)        {            byte[] btfile = null;            using (FileStream fs = new FileStream (filename, FileMode.Open, FileAccess.Read, FileShare.Read))            {                Btfile = New Byte[length];                Fs. Seek (start, seekorigin.begin);                Fs. Read (btfile, 0, length);            }            return btfile;        }

Converts a byte array to a string public        static string bytestostring (byte[] bt)        {            return Encoding.UTF8.GetString (BT);        }

Small bet

1, about C # encryption code, there are various online, we can refer to.

2, MD5 is not a cryptographic algorithm, but a digest algorithm. The encryption algorithm is reversible, and the abstract algorithm is theoretically irreversible. If MD5 is a cryptographic algorithm, then it is better to call him a super compression algorithm, because you enter any length of clear text to him, the result is a fixed length 16, 32, 64.

3, the encrypted information is written to the specified file, you can refer to the function of recording the text log.

4, the use of Combox control can refer to: Combox control.

The above is the C # cryptographic gadget code implementation content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!



  • Related Article

    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.