XML表的加密与解密

/// /// 加密解密key 必须32位. 

/// private const string EncryptKey = "332h034r78152dfs8sf56sf05e615w2s";

//内容加密.

public static string Encrypt(string toE)

{

byte[] keyArray = UTF8Encoding.UTF8.GetBytes(EncryptKey);

RijndaelManaged rDel = new RijndaelManaged();

rDel.Key = keyArray;

rDel.Mode = CipherMode.ECB;

rDel.Padding = PaddingMode.PKCS7;

ICryptoTransform cTransform = rDel.CreateEncryptor();

byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toE);

byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray,0,toEncryptArray.Length);

return Convert.ToBase64String(resultArray,0,resultArray.Length);

}

//内容解密

public static string Decrypt(string toD)

{

byte[] keyArray = UTF8Encoding.UTF8.GetBytes("332h034r78152dfs8sf56sf05e615w2s");

RijndaelManaged rDel = new RijndaelManaged();

rDel.Key = keyArray;

rDel.Mode = CipherMode.ECB;

rDel.Padding = PaddingMode.PKCS7;

ICryptoTransform cTransform = rDel.CreateDecryptor();

byte[] toEncryptArray = Convert.FromBase64String(toD);

byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray,0,toEncryptArray.Length);

return UTF8Encoding.UTF8.GetString(resultArray);

}

你可能感兴趣的:(XML表的加密与解密)