这一功能是当前类。我怎么称呼它?
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//------
//------
String r = EncryptText<Cryptography.Aes>(myTextStringToEncode);
}
private string EncryptText<TSymmetricAlgorithm>(string input) where TSymmetricAlgorithm : SymmetricAlgorithm, new()
{
var pwdBytes = Encoding.UTF8.GetBytes("MY560Secratekey38433661283912");
using (TSymmetricAlgorithm sa = new TSymmetricAlgorithm())
{
ICryptoTransform saEnc = sa.CreateEncryptor(pwdBytes, pwdBytes);
var encBytes = Encoding.UTF8.GetBytes(input);
var resultBytes = saEnc.TransformFinalBlock(encBytes, 0, encBytes.Length);
return Convert.ToBase64String(resultBytes);
}
}
}