How to make a signature?

I can do it by python as below:

import hmac
import hashlib
from urllib.parse import urlencode

secret_key = "sfsw............................esdfw2"
query_string = urlencode({"a": "a23a323", "b": "b23b45"}, True)
signature ="utf-8"), query_string.encode("utf-8"), hashlib.sha256).hexdigest()

Now I want to do this by Rust, I want to get a simple demo;

I think this is equivalent:

thanks for your reply;
The code prints as below:

[1D, 0E, E1, 45, AC, CA, 3E, FA, F2, CD, CE, 71, F2, 3F, FB, DC, C0, 99, 8D, AF, F5, 4D, 78, 55, E1, B3, F2, 76, 9E, 2C, 3D, BE]

Python code prints what looks like this:


Is this an implied question about formatting?

The bytes are the same as the output from your Python code - they're just formatted differently. If you output the bytes like this:

    for b in &code_bytes {
        print!("{:02x}", b);

you get exactly the same output as your original Python code.

thank you.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.