Hi,
I am trying to access Rapyd API and having problem creating signature.
To Create signature:
func sign(secret string, data []byte) string {
hash := hmac.New(sha256.New, []byte(secret))
hash.Write(data)
return hex.EncodeToString(hash.Sum(nil))
}
To create to_sign data:
//http_method e.g "get"
//path e.g "v1/data/countries"
//body e.g ""
//sample return value in string "get/v1/data/countriesa3d88998fcc545b41651211157_ accesskey_secret"
func to_sign(http_method, path, body, access_key, secret string) []byte {
//timestamp to string
ts := fmt.Sprintf("%d", time.Now().Unix())
//salt generation
key := make([]byte, 6)
rand.Read(key)
salt := fmt.Sprintf("%x", key)
http_method = strings.ToLower(http_method)
data := []byte(http_method + path + salt + ts + access_key + secret + body)
return data
}
Error returned
{"status":{"error_code":"UNAUTHENTICATED_API_CALL","status":"ERROR","message":"The API received a request, but the signature did not match. The request was rejected. Corrective action: (1) Remove all whitespace that is not inside a string. (2) Remove trailing zeroes and decimal points, or wrap numbers in a string.","response_code":"UNAUTHENTICATED_API_CALL","operation_id":"9306d5ea-8c39-4898-afaa-47fc06170aaa"}}
Go Version 1.18