日期:2014-05-18 浏览次数:20987 次
public static byte[] Encode(byte[] data) { byte[] byKey = KEY_64; byte[] byIV = IV_64; DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider(); int i = cryptoProvider.KeySize; MemoryStream ms = new MemoryStream(); CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateEncryptor(byKey, byIV), CryptoStreamMode.Write); cst.Write(data, 0, data.Length); cst.FlushFinalBlock(); byte[] buffer = ms.GetBuffer(); return buffer; } public static byte[] Decode(byte[] data) { byte[] byKey = KEY_64; byte[] byIV = IV_64; byte[] byEnc; byEnc = data; DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider(); MemoryStream ms = new MemoryStream(); CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateDecryptor(byKey, byIV), CryptoStreamMode.Read); cst.Read(byEnc, 0, (int)byEnc.Length); cst.FlushFinalBlock(); byte[] buffer = new byte[ms.Length]; ms.Read(buffer, 0, (int)ms.Length); return buffer; }