1//對稱加密幫助類
2public
static
class
cryptohelper3;
22 provider.key =encoding.utf8.getbytes(key);
2324 encryptor =provider.createencryptor();
25//
建立明文流
26byte clearbuffer =encoding.utf8.getbytes(encryptedtext);
27 memorystream clearstream = new
memorystream(clearbuffer);
2829
//建立空的密文流
30 memorystream encryptedstream = new
memorystream();
3132 cryptostream cryptostream =
33new
cryptostream(encryptedstream, encryptor, cryptostreammode.write);
3435
//將明文流寫入到buffer中
36//
將buffer中的資料寫入到cryptostream中
37int bytesread = 0;38
byte buffer = new
byte
[buffersize];
39do
40 while (bytesread > 0
);44
45cryptostream.flushfinalblock();
4647
//獲取加密後的文字
48 buffer =encryptedstream.toarray();
49string str =convert.tobase64string(buffer);
50return
str;51}
5253
//解密演算法
54///
55///
56///
為24或16位字元
57///
被解密的字串
58///
59public
static
string decrypt(string key, string
decryptedtext)60;
62 provider.key =encoding.utf8.getbytes(key);
6364 decryptor =provider.createdecryptor();
65byte encryptedbuffer =convert.frombase64string(decryptedtext);
66 stream encryptedstream = new
memorystream(encryptedbuffer);
6768 memorystream clearstream = new
memorystream();
69 cryptostream cryptostream =
70new
cryptostream(encryptedstream, decryptor, cryptostreammode.read);
7172
int bytesread = 0;73
byte buffer = new
byte
[buffersize];
7475
do76
while (bytesread > 0
);80
81 buffer =clearstream.getbuffer();
82string str =
83 encoding.utf8.getstring(buffer, 0, (int
)clearstream.length);
8485
return
str;86}
8788 }
對稱加密解密類
using system using system.collections.generic using system.web using system.security.cryptography using system.text using system.io using system.web.u...
C DES加密 解密幫助類
des加密 解密幫助類 system.web.security.formsauthentication.hashpasswordforstoringinconfigfile 這個已經廢棄了,是乙個在.net 4.5中已經廢棄不用的api,參見 private static string deskey...
對稱加密解密類c
namespace encryptdll else if sha1.computehash encoding.default.getbytes strkey length tdes.key.length 初始向量的設定 if sha1.computehash encoding.default.get...