I Have ruby method for creating signature for REST API call.
private static String sign_data(String str, String api_secret, bool cgi_escape)
{
String r = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), api_secret, str)).replace('\n','');
cgi_escape ? CGI.escape(r) : r
return r
}
can any one help me getting equivalent apex code? i tried writing the below apex code but couldn't succeed.
private static String sign_data(String str, String api_secret, bool cgi_escape)
{
String r =EncodingUtil.base64Encode((OpenSSL::Digest::SHA1.new, api_secret, str)).replace('\n','');
return r;
}
FIXED : Use the below solution
private static String sign_data(String str, String api_secret){
String algorithmName = 'HmacSHA1';
Blob hmacData = Crypto.generateMac(algorithmName,
Blob.valueOf(str), Blob.valueOf(api_secret));
return EncodingUtil.base64Encode(hmacData);
}