加密解密
//加密
public static string gdencode(string data, string key)
{
key = "12345678";
byte[] bykey = system.text.asciiencoding.ascii.getbytes(key);
byte[] byiv = system.text.asciiencoding.ascii.getbytes(key);
descryptoserviceprovider cryptoprovider = new descryptoserviceprovider();
int i = cryptoprovider.keysize;
memorystream ms = new memorystream();
cryptostream cst = new cryptostream(ms, cryptoprovider.createencryptor(bykey, byiv), cryptostreammode.write);
streamwriter sw = new streamwriter(cst);
sw.write(data);
sw.flush();
cst.flushfinalblock();
sw.flush();
return convert.tobase64string(ms.getbuffer(), 0, (int)ms.length);
}
//解密
public static string gjdecode(string data, string key)
{
key = "12345678";
byte[] bykey = system.text.asciiencoding.ascii.getbytes(key);
byte[] byiv = system.text.asciiencoding.ascii.getbytes(key);
byte[] byenc;
try
{
byenc = convert.frombase64string(data);
}
catch
{
return data;
}
descryptoserviceprovider cryptoprovider = new descryptoserviceprovider();
memorystream ms = new memorystream(byenc);
cryptostream cst = new cryptostream(ms, cryptoprovider.createdecryptor(bykey, byiv), cryptostreammode.read);
streamreader sr = new streamreader(cst);
string str;
str = sr.readtoend();
if (str.trim() == "") str = data;
return str;
}
下一篇: 电脑能卡到什么程度?卡到自己都笑了