1
使用PostSharp我願做現場攔截PostSharp場攔截加密和解密
加密/解密我有一個類
public class guestbookentry
{
[Encryption] // This Attribute has to Encrypt and Decrypt
public string Message { get; set; }
public string GuestName { get; set; }
}
我節省了Azure的表對象。只有特定的字段必須獲得En/Decrypt。上的字段攔截
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PostSharp;
using PostSharp.Aspects;
using EncryptionDecryption;
using PostSharp.Serialization;
using PostSharp.Aspects.Advices;
using PostSharp.Extensibility;
namespace GuestBook_Data
{
[Serializable]
public class EncryptionAttribute : LocationInterceptionAspect
{
[MulticastPointcut(Targets = MulticastTargets.Field, Attributes = MulticastAttributes.Instance)]
public override void OnSetValue(LocationInterceptionArgs args)
{
base.OnSetValue(args);
if (args.Value != null)
{
MD5CryptoServiceExample objMD5Encrypt = new MD5CryptoServiceExample();
args.Value = objMD5Encrypt.Encrypt(args.Value.ToString()).Replace(" ", "+");
args.ProceedSetValue();
}
}
public override void OnGetValue(LocationInterceptionArgs args)
{
base.OnGetValue(args);
if (args.Value != null)
{
MD5CryptoServiceExample objMD5Encrypt = new MD5CryptoServiceExample();
args.Value = objMD5Encrypt.Decrypt(args.Value.ToString()); //objMD5Encrypt.Decrypt(args.Value.ToString());
args.ProceedGetValue();
}
}
}
}
問題
PostSharp屬性是 1.連續加密和解密發生其是難以處理。
請建議