0

Ex : https://www.abc.com/home?firstname=C1SA8WkuxUncg4SLsHeirA==&lastname=23O5jzhBJUGA9f9KwDre2A==

Actually the above first name should display as suneel and last name as test.

I have tried with the below code but it doesn't work .

 Blob cryptoKey = Crypto.generateAesKey(128);        
 vFNameencrypt = ApexPages.currentPage().getParameters().get('firstname'); //Blob data = Blob.valueOf(vFNameencrypt);      
 Blob data = EncodingUtil.base64Decode(vFNameencrypt);
 Blob decryptedData = Crypto.decryptWithManagedIV('AES128',cryptoKey, data);        
//vFName = decryptedData.toString();

I am using this code for Salesforce Customer community portals.

4
  • 1
    It would depend on how it was encrypted and who encrypted it
    – Eric
    Commented Nov 19, 2018 at 5:21
  • i am assuming by adding the encrypted value in the Paremeter called first and last name and trying to decrypt in the application form. Here the URL parameter values are populating in the application form .I don't want to see the parameter values in the URL . I want parameter values in encrypted format and populated application form values in Decrypted format Commented Nov 19, 2018 at 5:24
  • 1
    You generally can’t decrypt unless you know how it was encrypted and the hashes used
    – Eric
    Commented Nov 19, 2018 at 5:27
  • Yes correct but i am encrypting my first and last name through one website which will generate in encrypted format ,that i am giving as parameter values and trying to decode it using the above code Commented Nov 19, 2018 at 5:50

1 Answer 1

1

"Encrypted" is not a format. Data is encrypted using a specific algorithm, key, initialization vector, mode of operation, and so forth. These values are not interchangeable. You must know exactly how data is being encrypted, and must possess the encryption key, in order to decrypt it successfully.

What you are doing here is providing encrypted data from an unknown source (whether or not it's encrypted using a method compatible with Salesforce) and asking Salesforce to attempt to decrypt it with a brand new key

Blob cryptoKey = Crypto.generateAesKey(128);        

rather than the key with which it was encrypted. This is essentially guaranteed to fail because that's simply not how encryption works.

4
  • Thanks David , unless we don't do encryption we cannot work on decryption ? Commented Nov 20, 2018 at 0:15
  • You need to have the person who is doing the encryption explain to you how it is done and provide you with the key details.
    – David Reed
    Commented Nov 20, 2018 at 0:21
  • Does salesforce support only AES 128,256 or we can try with other hash codes like Sha1 or md5 ? Commented Nov 20, 2018 at 0:33
  • Hash algorithms and ciphers are not the same thing. AES is a cipher. SHA1 and MD5 are hash algorithms. Hashes are one-way (not reversible). Salesforce supports AES128, 192, and 256. It does not support any other ciphers. Supported hash algorithms are MD5, SHA1, SHA-256, SHA-512.
    – David Reed
    Commented Nov 20, 2018 at 0:58

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