I'm storing user passwords for an external web service in salesforce, in encrypted fields. Using the SOAP API in JavaScript, I wish to use the password in a REST request. However, I'm unable to decrypt an encrypted field for use in this way. I could of course set the user profile to 'View Encrypted Data', but if I do this for every user it would defeat the point of the encryption in the first place. Is there a way around this or something I'm missing?


View Encrypted Data permission will allow the user to see the original value of the field both in the UI and via API.

You can use a permission set to add the "View Encrypted Data" permission to a specific user.

If you do add this permission, keep in mind that it is ORG WIDE for that user so you will have to be mindful of FLS for those encrypted fields you do not want them do see.....


One workaround would be to use custom encryption logic and store that data in a text field.

For instance, assuming you're using a web application, when a user registers or login you'd want to take that literal String, execute your logic (using as as secure methods as possible (e.g. bcrypt/PBKDF2/scrypt)) and either store (e.g. on registration) or compare (e.g. on login) that encrypted String.

In other words, particularly when it comes to passwords, you never want to work with the literal string nor would you want something to be easily decryptable lest you want to run the same risk Sony, Adobe, Kickstarter, Blue Ocean, Target and others have. The password data you hold in your database should be totally alien, even to you and your administrators.

Although not the best, someone had a similar question here.

Hope this helps.

  • 1
    Seems correct, though in my case I feel I may have found a workaround (untested as of now). In Apex, when I retrieve the field, it appears to be decrypted (though not in anonymous apex). Instead of querying for the data through the SOAP API, I can call apex remotely through JavaScript and pass back the password. In this way, I retrieve a decrypted copy of the password. This works, though to me it seems incredibly insecure.
    – Matyria
    Sep 1 '15 at 12:14
  • I've removed the first part of my answer as I'm don't believe I'm correct. However, the rest is probably relevant. Eric's answer regarding Encrypted Fields is almost certainly more accurate.
    – Dan Jones
    Sep 1 '15 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.