Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Edwin Beltran 4 posts 34 karma points
    Feb 14, 2015 @ 02:11
    Edwin Beltran
    0

    Encrypt/Decrypt Member Property

    I need to encrypt an sensitive property of the Members in the DB... The approach I am taking is this:

    public class MyEventHandler : ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            MemberService.Saving += MemberServiceOnSaving;
            base.ApplicationStarted(umbracoApplication, applicationContext);
        }
    
        private void MemberServiceOnSaving(IMemberService sender, SaveEventArgs<IMember> saveEventArgs)
        {
            //Logic to Encrypt and Save Goes Here!
        }
    }
    

    this is working to encrypt the value for the saving, but I dont know how to intercept the value to decrypt it when reading it... Any suggestions? Or if this is the right approach...

  • Luke 110 posts 256 karma points
    Feb 14, 2015 @ 11:11
    Luke
    0

    Hi,

    This approach seems fine to me - it is one that I have used.

    When reading it you would simply have a utility method Decrypt in a class somewhere. You would normally read the value when you have an instance of an IMember

    var m = MemberService.GetById(100);
    var decryptedVal = MyClass.Decrypt(m.Attribute);
    

    Hope that helps!

    Regards, L

  • Edwin Beltran 4 posts 34 karma points
    Feb 14, 2015 @ 15:05
    Edwin Beltran
    0

    Thanks L for replying... but I am talking about the Member Section in the CMS, see this screenshot: Member Section

    I need to intercept the call the CMS does to get the member and decrypt the value... Do I need to rewrite the Member section maybe to gain control on the MemberService.GetById() Method?

  • Luke 110 posts 256 karma points
    Feb 14, 2015 @ 15:42
    Luke
    100

    Ah, I see - my mistake, sorry.

    In that case have you thought about your own custom property editor? Then you can do the encrypting and decrypting in the getters and setter methods.

    Regards L

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Feb 14, 2015 @ 16:21
    Jeavon Leopold
    0

    Yes, I would also recommend custom editors and then you can use the ConvertDbToEditor and ConvertEditorToDb methods to encrypt/decrypt

  • Edwin Beltran 4 posts 34 karma points
    Feb 15, 2015 @ 14:37
    Edwin Beltran
    0

    Awesome L and Jeavon, will give it a try... but, seams the best solution... good idea! thanks...

Please Sign in or register to post replies

Write your reply to:

Draft