Signature Algorithm
Encrypt
- Get the current timestamp
${timestamp} - Combine
${timestamp}and request body (if the http method isPOST, the request body isjsontext, if the http method isGET, the request body is unescapequerystring, likename=foo&age=18is valid,name%3dfoo%26age%3d18is invalid) into a new string$content - Sign
$contentwithsha256andPKCS1V15, 1024 - Encode the signed bytes content to
base64
Example
We sign the following data. The timestamp is 1736233260, the RSA key is
-----The following key pairs are for testing only-----
-----BEGIN RSA PUBLIC KEY-----
MIGJAoGBAOFSnhqtuXXXXXXXXXXXXXXXXXXXXXXXX4Yih6hViOdSGd7imWmCSZyP
psl3TmLhUoB+rTzYDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXUM0f+AxlKYMj8OQ
AgDPmZG1a5ydFrje4PLytC7sUw3GP4TTk8xg6iMHmYPdRDv7AEWdAgMBAAE=
-----END RSA PUBLIC KEY-----
-----BEGIN RSA PRIVATE KEY-----
MIICXwIBAAKBgQDhUp4arbuNEzraJPsl3gfju+j12/1QCVOGIoeoVYjnUhne4plp
gkmcj6bJd05i4VKAfq082A3WK5WGJ4OnFZ+slIcY6TFg+EKeSuBs471DNH/gMZSm
DI/DkAIAz5mRtWuXXXXXXXXXXXXXXXXXxj+E05PMYOojB5mD3UQ7+wBFnQIDAQAB
AoGBAIqpeCi83516xw32EiSEleBdBIlA34vAoYj7ePZr5PtN+CPE2Von1rslYCO9
axzIwyfWTTATWbiCS9sqOAe78+1t3shU0ryXelWQ95LOdiMp0ZvU3ya6MzSVuiuL
6gOQYu8kzRqCzqvyMNdAHFMmP0XXXXXXXXXXXXXXXXXXZAtVAkEA/N6gl4tYJBef
e/Gxi7qhuIKz0mvfA/yieRuiVhXXXXXXXXXXXXXXXXXXbs45hh+n4bw8AA9k0bvi
3IBIdV/CbwJBAOQcsOPf+lrs4PXXXXXXXXXXXXXXXXXXxuerfPYMAzvJ7EU1u72o
/5V9zdim+hPq+9cvsqO7dkJx+cXXXXXXXXXXXXXXXXXXXXXXXXXXXaiIxOdCbbtc
MY4uV8noiqDRf/pvAkyMMM+nm5pXXXXXXXXXXXXXXXXXXXXXXXXXIUx1sZ85AkEA
15eWR4jEoXMIFkd7Onc6tKuJ8kokqfXXXXXXXXXXXXXXXXXXXXXBRxSjnIQUDwck
Bnj6KW1fk+UM29dUDjmTqQJBAITyP16XXXXXXXXXXXXXXXXXXXXXvgCxCzRRi5ph
IavMyjrhDKyBGZ0mI6eoREaC4bxl31RRkYtg9mNeU3TxsBM=
-----END RSA PRIVATE KEY-----
json request body:
{"merchantId":"305142568","clientId":"client_001","paymentType":"E_COMMERCE","merchantTradeNo":"af8c2d1-5b3e-4a9f-b6c7-8d2e1f3a4b5c","payId":"01JY2KM5QNPXR8S4HTJZT9BC12","status":"PAY_SUCCESS","amount":"100","currency":"USDT","currencyType":"crypto","createTime":1736233200,"paymentTime":1736233260,"finishTime":1736233260,"customer":{"externalUserId":"user123@merchant.com","userName":"John Doe","registerTime":1704067200,"kycCountry":"USA","uid":"104326789"}}
- Get the current timestamp 1736233260
- Combine${timestamp} and request body (if the http method is POST, the request body is json text, if the http method is GET, the request body is unescape query string, like name=foo&age=18 is valid, name%3dfoo%26age%3d18 is invalid) into a new string $content
1736233260{"merchantId":"305142568","clientId":"client_001","paymentType":"E_COMMERCE","merchantTradeNo":"af8c2d1-5b3e-4a9f-b6c7-8d2e1f3a4b5c","payId":"01JY2KM5QNPXR8S4HTJZT9BC12","status":"PAY_SUCCESS","amount":"100","currency":"USDT","currencyType":"crypto","createTime":1736233200,"paymentTime":1736233260,"finishTime":1736233260,"customer":{"externalUserId":"user123@merchant.com","userName":"John Doe","registerTime":1704067200,"kycCountry":"USA","uid":"104326789"}}
- Sign $contentwith sha256 and PKCS1V15, 1024
- Encode the encrypted bytes in base64
vOyN+NnfWppnhxS6y1D+CAllj6Z/3np1Tm+nrt16e/EDl4VZjU2sVPSS/cBcf5Hy/jBarA8Y7yrvYqJonJAsAZcFKu9twW2XWyMbURC63Iumh5gkAE9UEx4/irpX4W6KXhqc2+7wc1tapC5zfVWRMIQ5Dh+7VscxLY+/WjKb/Vw=
Decrypt
- Get
timestamp,signaturefrom request header. - Get request body (if the http method is
POST, the request body isjsontext, if the http method isGET, the request body isunescape querystring) - Combine
${timestamp}and response body into a new string$content - decode the signature bytes from base64.
- Encrypt string content with sha256 and verify signature base PKCS1V15,1024.
Example
We provided the following data.
vOyN+NnfWppnhxS6y1D+CAllj6Z/3np1Tm+nrt16e/EDl4VZjU2sVPSS/cBcf5Hy/jBarA8Y7yrvYqJonJAsAZcFKu9twW2XWyMbURC63Iumh5gkAE9UEx4/irpX4W6KXhqc2+7wc1tapC5zfVWRMIQ5Dh+7VscxLY+/WjKb/Vw=
The timestamp is 1736233260, the RSA key is
-----The following key pairs are for testing only-----
-----BEGIN RSA PUBLIC KEY-----
MIGJAoGBAOFSnhqtuXXXXXXXXXXXXXXXXXXXXXXXX4Yih6hViOdSGd7imWmCSZyP
psl3TmLhUoB+rTzYDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXUM0f+AxlKYMj8OQ
AgDPmZG1a5ydFrje4PLytC7sUw3GP4TTk8xg6iMHmYPdRDv7AEWdAgMBAAE=
-----END RSA PUBLIC KEY-----
-----BEGIN RSA PRIVATE KEY-----
MIICXwIBAAKBgQDhUp4arbuNEzraJPsl3gfju+j12/1QCVOGIoeoVYjnUhne4plp
gkmcj6bJd05i4VKAfq082A3WK5WGJ4OnFZ+slIcY6TFg+EKeSuBs471DNH/gMZSm
DI/DkAIAz5mRtWuXXXXXXXXXXXXXXXXXxj+E05PMYOojB5mD3UQ7+wBFnQIDAQAB
AoGBAIqpeCi83516xw32EiSEleBdBIlA34vAoYj7ePZr5PtN+CPE2Von1rslYCO9
axzIwyfWTTATWbiCS9sqOAe78+1t3shU0ryXelWQ95LOdiMp0ZvU3ya6MzSVuiuL
6gOQYu8kzRqCzqvyMNdAHFMmP0XXXXXXXXXXXXXXXXXXZAtVAkEA/N6gl4tYJBef
e/Gxi7qhuIKz0mvfA/yieRuiVhXXXXXXXXXXXXXXXXXXbs45hh+n4bw8AA9k0bvi
3IBIdV/CbwJBAOQcsOPf+lrs4PXXXXXXXXXXXXXXXXXXxuerfPYMAzvJ7EU1u72o
/5V9zdim+hPq+9cvsqO7dkJx+cXXXXXXXXXXXXXXXXXXXXXXXXXXXaiIxOdCbbtc
MY4uV8noiqDRf/pvAkyMMM+nm5pXXXXXXXXXXXXXXXXXXXXXXXXXIUx1sZ85AkEA
15eWR4jEoXMIFkd7Onc6tKuJ8kokqfXXXXXXXXXXXXXXXXXXXXXBRxSjnIQUDwck
Bnj6KW1fk+UM29dUDjmTqQJBAITyP16XXXXXXXXXXXXXXXXXXXXXvgCxCzRRi5ph
IavMyjrhDKyBGZ0mI6eoREaC4bxl31RRkYtg9mNeU3TxsBM=
-----END RSA PRIVATE KEY-----
- Get
timestamp,signaturefrom request header.timestamp=1736233260signature=[base64 encoded signature] - Get request body (if the http method is
POST, the request body is json text, if the http method isGET, the request body isunescape querystring)
{"merchantId":"305142568","clientId":"client_001","paymentType":"E_COMMERCE","merchantTradeNo":"af8c2d1-5b3e-4a9f-b6c7-8d2e1f3a4b5c","payId":"01JY2KM5QNPXR8S4HTJZT9BC12","status":"PAY_SUCCESS","amount":"100","currency":"USDT","currencyType":"crypto","createTime":1736233200,"paymentTime":1736233260,"finishTime":1736233260,"customer":{"externalUserId":"user123@merchant.com","userName":"John Doe","registerTime":1704067200,"kycCountry":"USA","uid":"104326789"}}
- Combine
${timestamp}and response body into a new string$content
1736233260{"merchantId":"305142568","clientId":"client_001","paymentType":"E_COMMERCE","merchantTradeNo":"af8c2d1-5b3e-4a9f-b6c7-8d2e1f3a4b5c","payId":"01JY2KM5QNPXR8S4HTJZT9BC12","status":"PAY_SUCCESS","amount":"100","currency":"USDT","currencyType":"crypto","createTime":1736233200,"paymentTime":1736233260,"finishTime":1736233260,"customer":{"externalUserId":"user123@merchant.com","userName":"John Doe","registerTime":1704067200,"kycCountry":"USA","uid":"104326789"}}
- Decode the signature bytes from base64
- Encrypt string content with sha256 and verify signature base PKCS1V15,1024