日期:2014-05-17 浏览次数:20462 次
public static string DESS(string src)
{
string des = string.Empty;
DESCryptoServiceProvider objDESCryptoServiceProvider = new DESCryptoServiceProvider();
objDESCryptoServiceProvider.Key = Encoding.ASCII.GetBytes("12345678");//密钥
objDESCryptoServiceProvider.Mode = CipherMode.ECB;
objDESCryptoServiceProvider.Padding = PaddingMode.None;
byte[] bysData = Encoding.UTF8.GetBytes(src);
byte[] bysFixSizeData = new byte[(int)Math.Ceiling(bysData.Length / 8.0) * 8];
Array.Copy(bysData, bysFixSizeData, bysData.Length);
byte[] bysEncrypted = objDESCryptoServiceProvider.CreateEncryptor().TransformFinalBlock(bysFixSizeData, 0, bysFixSizeData.Length);//加密
des = Convert.ToBase64String(bysEncrypted);//加密后的字符串
if (des.Equals("")) des = "error";
return des;
}