function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Elad Kaplan 3Elad Kaplan 3 

Encrypting a String to send in a URL

I have a string with Parameters and their values that i need to send in a URL to a website.

How can I encrypt it where the other party writing in PHP can decrypt it? 
Nitin PaliwalNitin Paliwal
Hi,
Try this code,

// Generate an AES key for the purpose of this sample.
// Normally this key should be stored in a protected custom setting
// or an encrypted field on a custom object
Blob cryptoKey = Crypto.generateAesKey(256);

// Generate the data to be encrypted.
Blob data = Blob.valueOf('Test data to encrypted');
// Encrypt the data and have Salesforce.com generate the initialization vector
Blob encryptedData = Crypto.encryptWithManagedIV('AES256', cryptoKey, data);


For more INFO go through below link,
https://developer.salesforce.com/page/Apex_Crypto_Class

I hope this sloves your problem.

Thanks
Nitin
 
Elad Kaplan 3Elad Kaplan 3
Thanks Nitin, but I need to generate a key myself and give to the PHP developer on the other end.

How can he decrypt it ?
Nitin PaliwalNitin Paliwal
Hi Elad,
Here is the blog for your php developer.

http://wpy.me/blog/15-encrypt-and-decrypt-data-in-php-using-aes-256

Thanks
Nitin
Elad Kaplan 3Elad Kaplan 3
Thanks Nitin, How can I turn the Blob (encryptedData) into a string that I can pass in the URL ?