AnsweredAssumed Answered

CornerStone HMAC SHA 512 Signature Generation

Question asked by sridhar371391 on May 8, 2018
Latest reply on May 9, 2018 by Sjaak Overgaauw

I have a secret key which is

j6hriaKY2iZi+Y2uo9JJldmO1Bq79XB8d1v2uHzAK0Zvy972mIs8ThsJSQeDlZJz+HzmLD6Q1MUZb5X1Zf9MzQ==

I have a string like below that I need to generate SHA 512 for using the secret key above

POST\nx-csod-api-key:1lie8ficql9h5\nx-csod-date:2015-09-08T11:27:32.000\n/services/api/sts/session.  Need a Groovy script.

 

Sample C# code to calculate the signature (API Key request)

http://rextester.com/UCVM71477 

//signature to acquire a session string apiId = "1lie8ficql9h5"; string apiSecret = "j6hriaKY2iZi+Y2uo9JJldmO1Bq79XB8d1v2uHzAK0Zvy972mIs8ThsJSQeDlZJz+HzmLD6Q1MUZb5X1Zf9MzQ==";  //build the string to sign //note the order of the entries is important. //The http headers must be in alphabetical order by key name string httpMethod = "POST"; string httpUrl = "/services/api/sts/session"; StringBuilder stringToSign = new StringBuilder(); stringToSign.Append(httpMethod).Append("\n")                     .AppendFormat("x-csod-api-key:{0}", apiId).Append("\n")     .AppendFormat("x-csod-date:{0}", DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.000")).Append("\n")     .Append(httpUrl);  /* produces the following string: *  POST\nx-csod-api-key:1lie8ficql9h5\nx-csod-date:2015-09-08T11:27:32.000\n/services/api/sts/session */  //Generate the signature string signature = string.Empty;  byte[] secretkeyBytes = Convert.FromBase64String(apiSecret); byte[] inputBytes = Encoding.UTF8.GetBytes(stringToSign.ToString()); using (var hmac = new HMACSHA512(secretkeyBytes)) {     byte[] hashValue = hmac.ComputeHash(inputBytes);     signature = System.Convert.ToBase64String(hashValue); }  /* * signature produced: * 3x5ETGSoqJa4vLl8gOFzdhxReOS0k8Nk2CpKVFN2A60ItF8wfP2tr+GUY2mELXjL90B57B5imLIrzou3ZQMfqQ== */

Outcomes