日期:2014-05-17 浏览次数:20742 次
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace DataCrypto
{
/// <summary>
/// 对称加密算法类
/// </summary>
public class SymmetricMethod
{
private SymmetricAlgorithm mobjCryptoService;
private string Key;
/// <summary>
/// 对称加密类的构造函数
/// </summary>
public SymmetricMethod()
{
mobjCryptoService = new RijndaelManaged();
Key = "Guz(%&hj7x89H$yuBI0456FtmaT5&fvHUFCy76*h%(HilJ$lhj!y6&(*jkP87jH7";
}
/// <summary>
/// 获得密钥
/// </summary>
/// <returns>密钥</returns>
private byte[] GetLegalKey()
{
string sTemp = Key;
mobjCryptoService.GenerateKey();
byte[] bytTemp = mobjCryptoService.Key;
int KeyLength = bytTemp.Length;
if (sTemp.Length > KeyLength)
sTemp = sTemp.Substring(0, KeyLength);
else if (sTemp.Length < KeyLength)
sTemp = sTemp.PadRight(KeyLength, ' ');
return ASCIIEncoding.ASCII.GetBytes(sTemp);
}
/// <summary>