Skip to content

Instantly share code, notes, and snippets.

@402332509
Forked from HemantShukla/MD5 in Apex
Created June 22, 2017 06:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save 402332509/8e306b6a9c0480b553ccdb74f5196ac6 to your computer and use it in GitHub Desktop.
Save 402332509/8e306b6a9c0480b553ccdb74f5196ac6 to your computer and use it in GitHub Desktop.
String key = 'hgdhdhhdjfh12ehsn';
String secret = 'DNf32sdsj747dhkjd8893jjjdjds7jjk';
//Generating current Unix timestamp (in seconds)
String getTime = string.valueOf(Datetime.Now().getTime()/1000);
String requestInput = key + secret + getTime;
Blob requestBlob = Blob.valueOf(requestInput);
Blob hash = Crypto.generateDigest('MD5', requestBlob);
//Need to convert into hex to generate the equivalent of md5(string) method of PHP.
String requestSignature = EncodingUtil.convertToHex(hash);
http h = new Http();
HttpRequest req = new HttpRequest();
//For security purpose, actual have been replaced with dashes
req.setEndpoint('https://www.---------/api/v1/-----/search?address=10313%2BSW%2');
req.setMethod('GET');
req.setHeader('Api-Key', key);
req.setHeader('Api-Signature', requestSignature);
HttpResponse res = h.send(req);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment