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

Encrypt in C# and decrypt using Apex.

I want to pass a field in the query string from asp .net to Apex . I want to encrypt the value of the field and then pass it in the query string. I am not sure how to approach this, are there any example code /links for same ? Basically i want to encrypt in C# and decrypt using Apex.

Keyur PatelKeyur Patel



I am not sure but you can't directly pass your querystring data to Apex page. You can try with HTTPPOST method to pass C# encrypt data to Apex. Please check encrypt and decrypt algorithm to support both side(C# and Apex).


Input Parameter :


URL : Your Apex URL

Parameters: Your Encrypt Data


Method : HttpPost

publicstring HttpPost(string URI, string Parameters)



WebRequest req = System.Net.WebRequest.Create(URI);

            req.ContentType =


            req.Method =



// Add parameters to post


byte[] data = System.Text.Encoding.ASCII.GetBytes(Parameters);

            req.ContentLength = data.Length;


Stream os = req.GetRequestStream();

            os.Write(data, 0, data.Length);



// Do the post and get the response.


WebResponse resp = req.GetResponse();


if (resp == null) returnnull;


StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());


return sr.ReadToEnd().Trim();



2) Second suggestion, you can also pass your data using Json or webservice



Keyur Patel