I’m making a proprietary API call, and need to add signature in the Request header.
I’m not sure if this can be done in make.
The rules are as follow
- Reverse the timestamp and append it to the original timestamp to form N1.
- Example:
- Original number (timestamp):
1592553037 - Reversed:
7303552951 - N1 =>
15925530377303552951
- Original number (timestamp):
- Convert each digit of N1 to its ASCII value, sum them, and then divide by 29, taking the remainder as N2.
- Convert each digit to its ASCII value and sum them:
- ‘1’ + ‘5’ + ‘9’ + ‘2’ + ‘5’ + ‘5’ + ‘3’ + ‘0’ + ‘3’ + ‘7’ + ‘7’ + ‘3’ + ‘0’ + ‘3’ + ‘5’ + ‘5’ + ‘2’ + ‘9’ + ‘5’ + ‘1’
- 49 + 53 + 57 + 50 + 53 + 53 + 51 + 48 + 51 + 55 + 55 + 51 + 48 + 51 + 53 + 53 + 50 + 57 + 53 + 49 = 1040
- N2 =>
1040 % 29 = 25 - Insert N2 into N1 at the 4th and 11th positions.
- Example:
1592255303577303552951(assuming N2 is ‘25’ inserted as two digits) - If N2 is less than 10, insert ‘0’ at the 4th position.
- (This step implies that if N2 was, for example, ‘5’, you’d insert ‘0’ at the 4th position and ‘5’ at the 11th, but the example in step 3 shows N2 inserted as a two-digit number. This needs clarification for precise implementation.)
- Prepend the password to the string.
- Example:
1234561592255303577303552951 - Perform SHA256 encryption on the resulting string.
- Generate the hexadecimal string and convert it to uppercase.
Here’s .net sample code
string num1 = "1234561592255303577303552951";
SHA256 sha256 = new SHA256CryptoServiceProvider();
byte[] source = Encoding.UTF8.GetBytes(num1 );
byte[] crypto = sha256.ComputeHash(source);
string result = string.Empty;
foreach (byte x in crypto)
{
result += string.Format("{0:x2}", x);
}
return result.ToUpper()