一聚教程网:一个值得你收藏的教程网站

热门教程

RC2加密算法在C#的应用----完善版

时间:2022-07-02 11:07:14 编辑:袖梨 来源:一聚教程网

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[]{106,51,25,141,157,142,23,111,234,159,187,154,215,34,37,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();
}
///
/// 新建一个大小为10261B的文件,以便将加密数据写入固定大小的文件。
///

/// 文件保存的地址,包含文件名
public void InitBinFile(string filePath)
{
byte[] tmp = new byte[10261];
try //创建文件流,将其内容全部写入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,0,10261);
writeFileStream.Flush();
writeFileStream.Close();
}

热门栏目