Unfortunately, I'm not sure that this is going to be possible using Apex. I created a test Java program (which works against the Google API) to observe the differences between what Java produces vs Apex. I noted the signatures generated from the two were different which narrowed it down to the output of the
I found this link which gives the following info:
The Apex Crypto class provides support for Digital Signatures with the
sign() method. The following considerations apply:
- The two algorithms are RSA and RSA-SHA1, which are functionally equivalent.
- A PKCS8 formatted private key in base64 decoded form is required. This private key should not be hardcoded in the Apex script but should
be stored in a protected custom setting or a encrypted fields in a
- It is equivalent to the Java Signature.sign() class method using "SHA1withRSA".
- In C#, it is the equivalent of (1) signing the clear text using SHA1Managed.ComputeHash() and (2) Signing using
RSACryptoServiceProvider.ComputeHash() against the resulting hash.
- Functionally, it will compute a SHA1 digest from clear text and encrypt the digest using RSA with the provided private key.
I have highlighted the key issue here, I believe you need the equivalent of SHA256withRSA which does not seem to be an option with the Crypto class (at least not that I can figure out).
So, in summary I think your code is correct but the signature being generated is not.
A good way to test this is to look at the generated debug SOQL at the bottom of the page and then run it in SOQL Xplorer or something. This will give you a good indication what is going on under the hood. For instance, when I entered 60 into the Amount field, the generated SOQL is:
select name, accountid, amount, closedate, forecastcategoryname, ownerid from opportunity where accountid != null and amount LIKE '60%' order by closedate desc limit 25
Since amount is a numeric field, and amount LIKE '60%' order is not going to work. You are constructing the SOQL as string values when some are numeric and dates. For instance, your amount section:
soql += ' and amount LIKE \''+String.escapeSingleQuotes(amount)+'%\'';
Should look something like:
soql += ' and amount > '+amount+''';