檔案加解密

2022-02-21 18:01:39 字數 2832 閱讀 8373

建立debuglzq ,

///

///密碼

//////

加密物件

private

static symmetricalgorithm createrijndael(string password, byte

salt)

//////

加密檔案隨機數生成

///

private

static randomnumbergenerator rand = new

rngcryptoserviceprovider();

//////

生成指定長度的隨機byte陣列

///

///byte陣列長度

///隨機byte陣列

private

static

byte generaterandombytes(int

count)

//////

加密檔案

///

///待加密檔案

///加密後輸入檔案

///加密密碼

public

static

void encryptfile(string infile, string outfile, string

password)

//關閉加密流

chash.flush();

chash.close();

//讀取雜湊

byte hash =hasher.hash;

//輸入檔案寫入雜湊

cout.write(hash, 0

, hash.length);

//關閉檔案流

cout.flush();

cout.close();}}

}//////

解密檔案

///

///待解密檔案

///解密後輸出檔案

///解密密碼

public

static

void decryptfile(string infile, string outfile, string

password)

if (slack > 0

)

chash.flush();

chash.close();

fout.flush();

fout.close();

byte curhash =hasher.hash;

//獲取比較和舊的雜湊物件

byte oldhash = new

byte[hasher.hashsize / 8

]; read = cin.read(oldhash, 0

, oldhash.length);

if ((oldhash.length != read) || (!checkbytearrays(oldhash, curhash)))

throw

new cryptohelpexception("

檔案被破壞");

}if (outvalue !=lsize)

throw

new cryptohelpexception("

檔案大小不匹配");}}

} }

using

system;

using

system.collections.generic;

using

system.componentmodel;

using

system.data;

using

system.drawing;

using

system.io;

using

system.linq;

using

system.text;

using

system.windows.forms;

namespace

jiami

private

void button1_click(object

sender, eventargs e)

private

void button3_click(object

sender, eventargs e)

}private

void button2_click(object

sender, eventargs e)}}

檔案加解密 解密版

include stdafx.h include des.h define crt secure no warnings include include include pragma warning disable 4996 int filesymenc const char pfile1,cons...

C 檔案簡單加解密

include include includevoid encfile char in filename,char pwd,char out filename 對檔案進行加密的具體函式 void decryptfile char in filename,char pwd,char out filen...

C語言(檔案加解密)

在c語言,檔案主要分為文字檔案和二進位制檔案,因此主要是對這兩種檔案進行加解密。原檔案 加密對每乙個字元進行 異或運算 規則 1 1 0,0 0 0,1 0 1,0 1 1 同為0,不同為1 void crpypt char file path,char crpypt path 關閉 fclose ...