data encryptionIn Part 1, we talked about creating a plugin which involved retrieving the certificate for encryption.

This blog, continues with the plugin and performing data encryption in Dynamics CRM and also Masking data on the form.

Data Encryption

After retrieving the web resource, we need to instantiate an X509 certificate and then use it to encrypt the data. You need to fist include the following namespaces in your plugin:



Once the strings are saved to the fields, Dynamics CRM stores this text as encrypted data as seen on this form:

encrypted fields

Data Masking

In addition to storing credit card numbers in encrypted format, they also need to be masked. The number is usually obfuscated by an ‘X’ in place of the numeric digit.

So all we do is create a function to manipulate the string for the credit card number and call it from the plugin:


So as you can see, the masked credit card number is produced on the CRM form below:

masked credit card number


So, combining steps from both Parts 1 & 2 to implement the storing of encrypted credit card information, we had to:

  • Generate an X509 certificate in order to encrypt credit card details
  • Create a webresource to store this certificate within CRM
  • Create a plugin that retrieves the webresource certificate
  • Get the customer’s credit card details when it is saved on a form and encrypt it using the certificate
  • Mask the credit card number
  • Finally in the plugin, save the encrypted information and masked credit card number in CRM.