2

We have a private rsa key and a secret phrase. How can I make a request signed with this?

I know how to make a request signed with a certificate, and it works, for example:

cert, err := tls.LoadX509KeyPair(path+"user.crt", path+"user.key")
if err != nil {
    log.Fatal(err)
}
tlsConfig := &tls.Config{
        Certificates: []tls.Certificate{cert},
    }
t := &http.Transport{
        TLSClientConfig: tlsConfig,
    }
client := &http.Client{
        Transport: t,
    }
.....
.....
resp, err := client.Do(request)

it worked fine…

but how can I do the same thing on Golang? Here is a example done on php:

....
$data = json_encode($data);

    $privateKey = openssl_pkey_get_private(
        file_get_contents(__DIR__ . 'private.pem'),
        file_get_contents(__DIR__ . 'password.txt')
    );
openssl_sign($data, $sign, $privateKey);
    $sign = base64_encode($sign);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'apiurl');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Content-Type: application/json',
        'Sign: ' . $sign,
    ]);

How we can get sign on Golang?

Wolfgang
  • 1,328
  • 2
  • 8
  • 11
codices
  • 49
  • 7
  • Does this answer your question? [Golang signing a struct using rsa](https://stackoverflow.com/questions/48730344/golang-signing-a-struct-using-rsa) – erik258 Dec 23 '21 at 23:10
  • hi,in your proposed topic, rsa key without a password – codices Dec 24 '21 at 08:49

0 Answers0