Application of RC2 encryption algorithm in C # ---- improved version
Source: Internet
Author: User
Using System;
Using System. Security. Cryptography;
Using System. Text;
Using System. IO;
Using System. Windows. Forms;
Namespace Curllion
{
Public class Crypt
{
Private byte [] key;
Private byte [] iv;
Private System. Text. ASCIIEncoding asciiEncoding;
Private System. Text. UnicodeEncoding textConverter;
Private RC2CryptoServiceProvider rc2CSP;
Public Crypt ()
{
InitializeComponent ();
}
Private void InitializeComponent ()
{
Key = new byte [] {25,141,157,142, 23,111,234,159,187,154,215, 204 };
Iv = new byte [] {135,186,133,136,184,149,153,144 };
AsciiEncoding = new System. Text. ASCIIEncoding ();
TextConverter = new System. Text. UnicodeEncoding ();
Rc2CSP = new RC2CryptoServiceProvider ();
}
/// <Summary>
/// Create a new file with a size of 10261B to write encrypted data to a fixed size file.
/// </Summary>
/// <Param name = "filePath"> address of the file, including the file name </param>
Public void InitBinFile (string filePath)
{
Byte [] tmp = new byte [1, 10261];
Try // create a file stream and write all its content to 0
{
System. IO. FileStream writeFileStream = new FileStream (filePath,
System. IO. FileMode. Create,
System. IO. FileAccess. Write,
System. IO. FileShare. None, 512, false );
For (int I = 0; I <10261; I ++)
Tmp [I] = 0;
WriteFileStream. Write (tmp );
WriteFileStream. Flush ();
WriteFileStream. Close ();
}
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