Encrypt MD5

The hash encryption algorithm is described in this section.

The provider requested with MD5 encrypted signature. For example, if request is:

{"key1": "value1", "key2": "value2", "key3": "value3" }

Step 1: Construct raw signature string in query string format and append with secret key. Keys are in lower case and are sorted in alphabetic order. Those key pairs with no value are omitted.

var rawData string = key1=value1&key2=value2&key3=value3 + SecretKey

Example:

{"app_id": "TEST", "token": "31a250ac789e47123456","timestamp": 1658287156}

AppId: TEST
Token: 31a250ac789e47
Timestamp: 1658287156
Secretkey: 123456

var rawData string = app_id=TEST&timestamp=1658287156&token=31a250ac789e47123456
// 64d4091c812e11f8887a727d000f573b

Step 2: Use secret key with MD5 encryption algorithm to encrypt data.

func encryptMD5(form interface{}, secret string) string {
	var newHash string

	v, _ := query.Values(form)
	v.Del("hash")

	text, _ := url.PathUnescape(v.Encode())

	hash := md5.Sum([]byte(text + secret))
	newHash = hex.EncodeToString(hash[:])

	return newHash
}

Last updated