using System;
using System
using System
using System
//方法
//加密方法
public string Encrypt(string pToEncrypt
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
//把字符串放到byte數組中
//原來使用的UTF
byte[] inputByteArray = Encoding
//byte[] inputByteArray=Encoding
//建立加密對象的密鑰和偏移量
//原文使用ASCIIEncoding
//使得輸入密碼必須輸入英文文本
des
des
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms
//Write the byte array into the crypto stream
//(It will end up in the memory stream)
cs
cs
//Get the data back from the memory stream
StringBuilder ret = new StringBuilder();
foreach(byte b in ms
{
//Format as hex
ret
}
ret
return ret
}
//解密方法
public string Decrypt(string pToDecrypt
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
//Put the input string into the byte array
byte[] inputByteArray = new byte[pToDecrypt
for(int x =
{
int i = (Convert
inputByteArray[x] = (byte)i;
}
//建立加密對象的密鑰和偏移量
des
des
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms
//Flush the data through the crypto stream into the memory stream
cs
cs
//Get the decrypted data back from the memory stream
//建立StringBuild對象
StringBuilder ret = new StringBuilder();
return System
}
//
注意
本人使用Windows
From:http://tw.wingwit.com/Article/program/net/201311/13609.html