<p>The issue is that your salt is a byte array, which you are passing directly as the hmac key, and then printing out the hex. This would require bitcoind to interpret the salt hex as a hex string and convert it to the bytes represented by the hex. However that is not what bitcoind does.</p>
<p>Bitcoind takes the salt as is, and uses it directly has the hmac key. So you need to do the same thing - convert the byte array to a string, and use the bytes of that string as the key.</p>
<p>This code works:</p>
<pre><code>user := &quot;kotal&quot;
password := &quot;s3cr3t&quot;

salt_data := make([]byte, 16)
rand.Read(salt_data)

salt := hex.EncodeToString(salt_data)

hash := hmac.New(sha256.New, []byte(salt))
hash.Write([]byte(password))

rpcauth := fmt.Sprintf(&quot;%s:%s$%x&quot;, user, salt, hash.Sum(nil))
</code></pre>

CC BY-SA 4.0
2022-03-22T14:21:35.160Z
2022-03-22T14:21:35.160Z
Ava Chow
<p>You could use or take inspiration from <a href="https://github.com/bitcoin/bitcoin/tree/7fcf53f7b4524572d1d0c9a5fdc388e87eb02416/share/rpcauth" rel="nofollow noreferrer">the <code>rpcauth</code> script in the Bitcoin Core repository</a> that does exactly this, but in Python.</p>

CC BY-SA 4.0
2022-03-17T16:00:54.393Z
we've cloned this script into go,  but it doesn't work
Farghaly
CC BY-SA 4.0
2022-03-17T15:56:44.750Z
2022-03-17T15:56:44.750Z
Antoine Poinsot
<p>We're developing a Blockchain deployment solution <a href="https://kotal.co" rel="nofollow noreferrer">kotal</a>, and generating -rpcauth argument from the supplied user name and password.
The problem is when we try to use the same user and password using curl, it writes <code>ThreadRPCServer incorrect password attempt from 127.0.0.1:55566</code>.</p>
<p>Here's how we're generating -rpcauth from password in golang.</p>
<pre><code>user := &quot;kotal&quot;
password = &quot;s3cr3t&quot;

salt := make([]byte, 16)
rand.Read(salt)

hash := hmac.New(sha256.New, salt)
hash.Write([]byte(password))

rpcauth := fmt.Sprintf(&quot;%s:%x$%x&quot;, user, salt, hash.Sum(nil))
</code></pre>
<p>What's wrong with our golang implementation ?</p>

CC BY-SA 4.0
2022-03-15T16:30:06.070Z
What you are adding to your `bitcoin.conf`? You need to pass exactly what is there, and core will get the hash.
Davidson Souza
CC BY-SA 4.0
2022-03-17T15:57:01.757Z
@DavidsonSouza so I can't simply pass --rpcauth cli argument to bitcoin process ?
Farghaly
<bitcoin-core><bitcoind><json-rpc><go-lang>
Generating bitcoin core -rpcauth argument using golang
Farghaly
# Generating bitcoin core -rpcauth argument using golang

(Asked by: username_0 on 2022-03-15)

We're developing a Blockchain deployment solution [kotal](https://kotal.co), and generating -rpcauth argument from the supplied user name and password.
The problem is when we try to use the same user and password using curl, it writes `ThreadRPCServer incorrect password attempt from 127.0.0.1:55566`.

Here's how we're generating -rpcauth from password in golang.

```
user := "kotal"
password = "s3cr3t"

salt := make([]byte, 16)
rand.Read(salt)

hash := hmac.New(sha256.New, salt)
hash.Write([]byte(password))

rpcauth := fmt.Sprintf("%s:%x$%x", user, salt, hash.Sum(nil))

```

What's wrong with our golang implementation ?

**Tags:** bitcoin-core, bitcoind, json-rpc, go-lang

> **Comments:**
> **username_1**: What you are adding to your `bitcoin.conf`? You need to pass exactly what is there, and core will get the hash.  
> **username_0**: @username_1 so I can't simply pass --rpcauth cli argument to bitcoin process ?  

---

## 2 answers

### Answer by username_2 on 2022-03-22. Score: 1 | Accepted answer

The issue is that your salt is a byte array, which you are passing directly as the hmac key, and then printing out the hex. This would require bitcoind to interpret the salt hex as a hex string and convert it to the bytes represented by the hex. However that is not what bitcoind does.

Bitcoind takes the salt as is, and uses it directly has the hmac key. So you need to do the same thing - convert the byte array to a string, and use the bytes of that string as the key.

This code works:

```
user := "kotal"
password := "s3cr3t"

salt_data := make([]byte, 16)
rand.Read(salt_data)

salt := hex.EncodeToString(salt_data)

hash := hmac.New(sha256.New, []byte(salt))
hash.Write([]byte(password))

rpcauth := fmt.Sprintf("%s:%s$%x", user, salt, hash.Sum(nil))

```


---

### Answer by username_3 on 2022-03-17. Score: 0

You could use or take inspiration from [the `rpcauth` script in the Bitcoin Core repository](https://github.com/bitcoin/bitcoin/tree/7fcf53f7b4524572d1d0c9a5fdc388e87eb02416/share/rpcauth) that does exactly this, but in Python.

> **Comments:**
> **username_0**: we've cloned this script into go,  but it doesn't work  

---

