模塊編號
包含
作者
審核
編寫日期
描述
如果模塊有修改
Log編號
修改作者
修改日期
修改描述
using System
using System
using System;
using System
using System
namespace LHCHIP
/**//// <summary>
/// 對稱加密算法類
/// </summary>
public class DecryptEncrypt
/**//// <summary>
/// 返回自身的一個類
/// </summary>
public static DecryptEncrypt MyDecryptEncrypt
get
return new DecryptEncrypt();
}
}
private SymmetricAlgorithm mobjCryptoService;
private string Key;
/**//// <summary>
/// 對稱加密類的構造函數
/// </summary>
internal DecryptEncrypt()
mobjCryptoService = new RijndaelManaged();
Key =
}
/**//// <summary>
/// 獲得密鑰
/// </summary>
/// <returns>密鑰</returns>
private byte[] GetLegalKey()
string _TempKey = Key;
mobjCryptoService
byte[] bytTemp = mobjCryptoService
int KeyLength = bytTemp
if (_TempKey
_TempKey = _TempKey
else if (_TempKey
_TempKey = _TempKey
return ASCIIEncoding
}
/**//// <summary>
/// 獲得初始向量IV
/// </summary>
/// <returns>初試向量IV</returns>
private byte[] GetLegalIV()
string _TempIV =
mobjCryptoService
byte[] bytTemp = mobjCryptoService
int IVLength = bytTemp
if (_TempIV
_TempIV = _TempIV
else if (_TempIV
_TempIV = _TempIV
return ASCIIEncoding
}
/**//// <summary>
/// 加密方法
/// </summary>
/// <param name=
/// <returns>經過加密的串</returns>
public string Encrypto(string Source)
byte[] bytIn = UTF
MemoryStream ms = new MemoryStream();
mobjCryptoService
mobjCryptoService
//創建對稱加密器對象
ICryptoTransform encrypto = mobjCryptoService
//定義將數據流鏈接到加密轉換的流
CryptoStream cs = new CryptoStream(ms
cs
cs
ms
byte[] bytOut = ms
return Convert
}
/**//// <summary>
/// 解密方法
/// </summary>
/// <param name=
/// <returns>經過解密的串</returns>
public string Decrypto(string Source)
byte[] bytIn = Convert
MemoryStream ms = new MemoryStream(bytIn
mobjCryptoService
mobjCryptoService
//創建對稱解密器對象
ICryptoTransform encrypto = mobjCryptoService
//定義將數據流鏈接到加密轉換的流
CryptoStream cs = new CryptoStream(ms
StreamReader sr = new StreamReader(cs);
return sr
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/11770.html