加密解密
//////
異常處理類
/// public
class
}//////
crypthelp
///
private
const
ulong fc_tag = 0xfc010203040506cf
;
private
const
int buffer_size = 128 * 1024
;
//////
檢驗兩個byte陣列是否相同
/// ///
byte陣列
///byte陣列
///true-相等
private
bool checkbytearrays(byte b1, byte
b2)return
true
; }
return
false
; }
//////
建立debuglzq ,
/// ///
密碼 ///
///加密物件
private symmetricalgorithm createrijndael(string password, byte
salt)
//////
加密檔案隨機數生成
/// private randomnumbergenerator rand = new
rngcryptoserviceprovider();
//////
生成指定長度的隨機byte陣列
/// ///
byte陣列長度
///隨機byte陣列
private
byte generaterandombytes(int
count)
//////
加密檔案
/// ///
待加密檔案
///加密後輸入檔案
///加密密碼
public
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
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("
檔案大小不匹配");}}
private
void button1_click(object
sender, eventargs e)
}private
void button2_click(object
sender, eventargs e)
else
foreach (fileinfo file in
allfile)
= string.empty;
messagebox.show("
加密成功");}}
private
void button3_click(object
sender, eventargs e)
else
foreach (fileinfo file in
allfile)
= string.empty;
messagebox.show("
解密成功");}}
}}
用openssl對檔案加密及解密
openssl是乙個開源的用以實現ssl協議的產品,它主要包括了三個部分 密碼演算法庫 應用程式 ssl協議庫。openssl實現了ssl協議所需要的大多數演算法。下面我將單介紹使用openssl進行檔案的對稱加密操作。一 openssl支援的加密演算法有 aes 128 cbc aes 128 c...
python RSA 公私鑰 對檔案加密解密
使用rsa模組 import rsa import base64 讀取私鑰 privkey rsa.privatekey.load pkcs1 open private.pem rb read 讀取公鑰 pubkey rsa.publickey.load pkcs1 open public.pem ...
對檔案進行簡單加密和解密操作
加密過程 利用fread函式將檔案以乙個位元組的形式依次讀出,對取出的位元組進行 1操作,然後再用fwrite函式寫入 void testencrypt char bytes fread bytes,1,1,fpread bytes 1 fwrite bytes,1,1,fpwrite printf...