0

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 ?

3
  • 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" ? Jun 13, 2014 at 9:02
  • just want to display them as encrypted format
    – user8597
    Jun 13, 2014 at 9:44
  • Ok, cool. I have stuck what I hope is a useful answer on here :) Jun 13, 2014 at 10:21

1 Answer 1

2

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',
                                                                     Crypto.generateAesKey(256), 
                                                                     Blob.valueOf(String.valueOf(myHash))));
    }

and the accompanying Visualforce page

<apex:page controller="HashMeUp">

    <h1>{!myHash}</h1>

</apex:page>

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

tgcwXMgmta06XPyYQWmSKU/NUmj8RIdHxpSWTXhCaG0=

The encoded version of the string..

See:

encrypted

Is that sort of what you are after??

4
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. Jun 13, 2014 at 9:33
  • Calm down @AtulRajguru9 - I explained what I was doing in the edit. Jun 13, 2014 at 10:17
  • Super Kool.... This is exactly what i was looking for ...
    – user8597
    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. 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 .