I am calling webservice in my Apex class. I don't want to store the information in Salesforce. I am showing the information in VF page using wrapper class. But now i need to display few of the fields in encrypted format. Is it possible ?

  • Do you mean you want to display them as if they had been stored as encrypted custom fields, or just that you want to display them in "an encrypted format" ? Commented Jun 13, 2014 at 9:02
  • just want to display them as encrypted format
    – user8597
    Commented Jun 13, 2014 at 9:44
  • Ok, cool. I have stuck what I hope is a useful answer on here :) Commented Jun 13, 2014 at 10:21

1 Answer 1


If you have an Apex class providing information to a Visualforce page, and you wish to "encrypt" some of the fields before displaying them... could you use the Apex standard Crypto library?

You can read more on the Crypto class in the docs. Note that in order to display the encrypted value of the string on the page I had to run it through the Base64 encoding class too.

So as an example, if you had a super simple controller like:

public class HashMeUp() {

    public string myHash = 'Hello World!';

    public string getMyHash() {

        return EncodingUtil.Base64Encode(Crypto.encryptWithManagedIV('AES256',

and the accompanying Visualforce page

<apex:page controller="HashMeUp">



You would not see "Hello World!" on your page, as you might expect from your variable instantiation, you would see this:


The encoded version of the string..



Is that sort of what you are after??

  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. Commented Jun 13, 2014 at 9:33
  • Calm down @AtulRajguru9 - I explained what I was doing in the edit. Commented Jun 13, 2014 at 10:17
  • Super Kool.... This is exactly what i was looking for ...
    – user8597
    Commented Jun 15, 2014 at 5:53
  • 1
    fyi: In reference to your edit comment (chill pills :p) Simon, posts under a certain amount of characters are automatically flagged as "low quality" and get queued as such in the review queues. Commented Jun 20, 2014 at 11:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .