usingsystem;
using
system.text;
using
system.security.cryptography;
using
system.io;
using
system.linq;
//摘自
#region
對稱加密類
//////
對稱加密解密類
///public
static
class
symmetricencryptclass
else
if(sha1.computehash(encoding.default.getbytes(strkey)).length
<
tdes.key.length)
//初始向量的設定
if(sha1.computehash(encoding.default.getbytes(strnameplusbirthday)).length
>
tdes.iv.length)
else
if(sha1.computehash(encoding.default.getbytes(strnameplusbirthday)).length
<
tdes.iv.length)
byte
encryptbuffer
=encoding.default.getbytes(strmsg);
memorystream streammemory
=new
memorystream();
cryptostream crystream
=null;//
加密流byte
readbuffer;
//用來接受加密資料
trycatch
finally
return
readbuffer;
}#endregion
#region
對稱解密**
//////
對稱解密方法
//////
需要解密的資料
///解密key
///解密向量
///解密後的資料
public
static
string
symmetricdecryptionfunction(
this
byte
bufmsg,
string
key,
string
iv)else
if(sha1.computehash(encoding.default.getbytes(strkey)).length
<
tdes.key.length)
//初始向量的設定
if(sha1.computehash(encoding.default.getbytes(strnameplusbirthday)).length
>
tdes.iv.length)
else
if(sha1.computehash(encoding.default.getbytes(strnameplusbirthday)).length
<
tdes.iv.length)
byte
readbuffer
=bufmsg;
memorystream streamread
=new
memorystream(readbuffer);
cryptostream decrystream
=null
;byte
bufferreader;
tryfinally
string
decrystring
=encoding.default.getstring(bufferreader);
return
decrystring;
}#endregion
}#endregion
對稱加密解密類
using system using system.collections.generic using system.web using system.security.cryptography using system.text using system.io using system.web.u...
非對稱加密類
摘自 using system using system.text using system.security.cryptography 非對稱加密類 public static class asymmetricencrytclass endregion region 非對稱加密 非對稱加密方法 要...
加密解密幫助類(對稱加密)
1 對稱加密幫助類 2public static class cryptohelper3 22 provider.key encoding.utf8.getbytes key 2324 encryptor provider.createencryptor 25 建立明文流 26byte clearb...