<Serializable(), AttributeUsage(AttributeTargets.Field)> _Public Class EncryptedFieldAttribute Inherits Attribute Private _VectorField As String = "" Private _Scheme As EncryptionSchemes = EncryptionSchemes.None Private _DatabaseDataType As DataTypes = DataTypes.Text Public ReadOnly Property Scheme() As EncryptionSchemes Get Return _Scheme End Get End Property ' ?? the underlying data storage type might be Varchar, but the public property could be Int Public ReadOnly Property DatabaseDataType() As PaladinDbType Get Return _DatabaseDataType End Get End Property Public ReadOnly Property VectorField() As String Get Return _VectorField End Get End Property Public Sub New() MyClass.New(EncryptionSchemes.None, "", PaladinDbType.Text) End Sub Public Sub New(ByVal Scheme As EncryptionSchemes) MyClass.New(Scheme, "", DataTypes.Text) End Sub Public Sub New(ByVal Scheme As EncryptionSchemes, ByVal VectorField As String) MyClass.New(Scheme, VectorField, DataTypes.Text) End Sub Public Sub New(ByVal Scheme As EncryptionSchemes, ByVal VectorField As String, ByVal DatabaseDataType As PaladinDbType) _Scheme = Scheme _VectorField = VectorField _DatabaseDataType = DatabaseDataType End SubEnd Class
Public Enum EncryptionSchemes None Hashed ' MD5, one-way encryption PublicVector ' RijndaelManaged (using an application level vector) PrivateVector ' RijndaelManaged (using a row level vector -- highest security) Custom ' User overridableEnd Enum
' hashed password value
<DataField("tblUsers", "tblUsers", "Password", "Password", true, 255, false, false, false, 0, 0, PaladinDbType.NVarchar), _ EncryptedField(EncryptionSchemes.Hashed)> _Friend Password As System.String = String.Empty' private vector value, points to another field for the vector value<DataField("tblUsers", "tblUsers", "SSN", "SSN", true, 255, false, false, false, 0, 0, PaladinDbType.NVarchar), _ EncryptedField(EncryptionSchemes.PrivateVector, "SSN_Key")> _Friend SSN As System.String = String.Empty' private vector key value -- key is generated on insert<DataField("tblUsers", "tblUsers", "SSN_Key", "SSN_Key", true, 255, false, false, false, 0, 0, PaladinDbType.NVarchar)> _Friend SSN_Key As System.String = String.Empty' private vector value, points to another field for the vector value<DataField("tblUsers", "tblUsers", "Salary", "Salary", true, 8, false, false, false, 8, 4, PaladinDbType.Real), _ EncryptedField(EncryptionSchemes.Custom)> _Friend Salary As Double = 0' overriden EntityBase.Encrypt/Decrypt methodsProtected Overrides Function Encrypt(ByVal Field As String) As String select case Field.ToLower case "salary" Return {some custom algorithm to encrpyt) Case Else Return MyBase.Encrypt(Field) End SelectEnd FunctionProtected Overrides Function Decrypt(ByVal Field As String, ByVal Value As String) As String select case Field.ToLower case "salary" Return {some custom algorithm to decrpyt) Case Else Return MyBase.Decrypt(Field, Value) End Select End Function
Hi Mike,
I think it is pretty overkill to build that into the framework as I feel that the data can actually be encrypted before assigning to the entities. I have not came across such requirements.
Anyway, I will have to temporary stop implementing new features into the framework to buy more time for myself to learn up .NET 2.0.