<p>So after some experiments, the answer is to</p>
<p>Remove the first 2 bytes (5820) from the cborhex and pipe the output to bech32 with addr_vk</p>
<p>For example</p>
<pre><code>$ cat vkey
{
    &quot;type&quot;: &quot;PaymentVerificationKeyShelley_ed25519&quot;,
    &quot;description&quot;: &quot;Payment Verification Key&quot;,
    &quot;cborHex&quot;: &quot;5820ba6e94a603da493604a0e0d0e8c4f3465ba299a0d0967a1cafd4c0fa0ab882ad&quot;
}

$ echo &quot;ba6e94a603da493604a0e0d0e8c4f3465ba299a0d0967a1cafd4c0fa0ab882ad&quot; | bech32 addr_vk &gt; vkeystring

$ cardano-cli address key-hash --payment-verification-key $(cat vkeystring)
$ cardano-cli address key-hash --payment-verification-key-file vkey 
</code></pre>
<p>Both key-hash should be the same.</p>

CC BY-SA 4.0
2021-11-28T20:33:38.653Z
thank you for the answer! What are the first 2 bytes?
fsquirrel
CC BY-SA 4.0
2021-07-22T19:40:20.017Z
2021-07-22T19:40:20.017Z
Alan Saw
<p>As Alan has already answered this for himself I'd like to add that when using an extended verification key you can produce the non-extended key first and then bech32 encode it to produce the hash.</p>
<p>For example, produce non-extended verification key from extended one:</p>
<pre><code>$ cat acct.vkey
  {
      &quot;type&quot;: &quot;PaymentExtendedVerificationKeyShelley_ed25519_bip32&quot;,
      &quot;description&quot;: &quot;Payment Verification Key&quot;,
      &quot;cborHex&quot;: &quot;58406d2d6c3e1bf46cfab0977279105a87bb89adb4c6dac3eb25ea2f300ef3e9aa0af720099909a8f7a871db0cb1b2158549cedd2019d60d7ac6c4891bf03cfdc652&quot;
  }
$ cardano-cli key non-extended-key --extended-verification-key-file acct.vkey --verification-key-file acct_short.vkey
$ cat acct_short.vkey
  {
      &quot;type&quot;: &quot;PaymentVerificationKeyShelley_ed25519&quot;,
      &quot;description&quot;: &quot;&quot;,
      &quot;cborHex&quot;: &quot;58206d2d6c3e1bf46cfab0977279105a87bb89adb4c6dac3eb25ea2f300ef3e9aa0a&quot;
  }
</code></pre>
<p>Remove first 2 bytes from non-extended key and produce valid encoded address (bech32 binary is included in <a href="https://github.com/input-output-hk/cardano-wallet/releases" rel="nofollow noreferrer">wallet release bundle</a>):</p>
<pre><code>$ echo &quot;6d2d6c3e1bf46cfab0977279105a87bb89adb4c6dac3eb25ea2f300ef3e9aa0a&quot; | bech32 addr_vk
  addr_vk1d5kkc0sm73k04vyhwfu3qk58hwy6mdxxmtp7kf029ucqaulf4g9q8d6yzn
</code></pre>
<p>Produce key hashes and compare:</p>
<pre><code>$ cardano-cli address key-hash --payment-verification-key addr_vk1d5kkc0sm73k04vyhwfu3qk58hwy6mdxxmtp7kf029ucqaulf4g9q8d6yzn
ad2704179252c6343d8e27708b725656ec30bc8a347dbb42bfd5509a
$ cardano-cli address key-hash --payment-verification-key-file acct.vkey 
ad2704179252c6343d8e27708b725656ec30bc8a347dbb42bfd5509a
</code></pre>

CC BY-SA 4.0
2021-07-29T14:07:02.340Z
2021-07-29T14:07:02.340Z
james
<p>In the <code>cardano-cli</code> tool,</p>
<p>it is possible to accept both <code>--payment-verification-key-file</code> and <code>--payment-verification-key</code> when running <code>cardano-cli address key-hash</code>
From the docs, it seems that the <code>--payment-verification-key</code> is supposed to be bech32 encoded.</p>
<p>But it is unclear how that is achieved.</p>
<p>How can I convert from the key-file to the key-string?</p>

<wallet><cardano-cli>
cardano-cli verification key bech32 encoding
# cardano-cli verification key bech32 encoding

(Asked by: username_0 on 2021-07-21)

In the `cardano-cli` tool,

it is possible to accept both `--payment-verification-key-file` and `--payment-verification-key` when running `cardano-cli address key-hash`
From the docs, it seems that the `--payment-verification-key` is supposed to be bech32 encoded.

But it is unclear how that is achieved.

How can I convert from the key-file to the key-string?

**Tags:** wallet, cardano-cli

---

## 2 answers

### Answer by username_0 on 2021-07-22. Score: 1 | Accepted answer

So after some experiments, the answer is to
Remove the first 2 bytes (5820) from the cborhex and pipe the output to bech32 with addr_vk
For example
$ cat vkey
{
    "type": "PaymentVerificationKeyShelley_ed25519",
    "description": "Payment Verification Key",
    "cborHex": "5820ba6e94a603da493604a0e0d0e8c4f3465ba299a0d0967a1cafd4c0fa0ab882ad"
}

$ echo "ba6e94a603da493604a0e0d0e8c4f3465ba299a0d0967a1cafd4c0fa0ab882ad" | bech32 addr_vk > vkeystring

$ cardano-cli address key-hash --payment-verification-key $(cat vkeystring)
$ cardano-cli address key-hash --payment-verification-key-file vkey 

Both key-hash should be the same.

> **Comments:**
> **username_1**: thank you for the answer! What are the first 2 bytes?  

---

### Answer by username_2 on 2021-07-29. Score: 1

As Alan has already answered this for himself I'd like to add that when using an extended verification key you can produce the non-extended key first and then bech32 encode it to produce the hash.
For example, produce non-extended verification key from extended one:
$ cat acct.vkey
  {
      "type": "PaymentExtendedVerificationKeyShelley_ed25519_bip32",
      "description": "Payment Verification Key",
      "cborHex": "58406d2d6c3e1bf46cfab0977279105a87bb89adb4c6dac3eb25ea2f300ef3e9aa0af720099909a8f7a871db0cb1b2158549cedd2019d60d7ac6c4891bf03cfdc652"
  }
$ cardano-cli key non-extended-key --extended-verification-key-file acct.vkey --verification-key-file acct_short.vkey
$ cat acct_short.vkey
  {
      "type": "PaymentVerificationKeyShelley_ed25519",
      "description": "",
      "cborHex": "58206d2d6c3e1bf46cfab0977279105a87bb89adb4c6dac3eb25ea2f300ef3e9aa0a"
  }

Remove first 2 bytes from non-extended key and produce valid encoded address (bech32 binary is included in wallet release bundle):
$ echo "6d2d6c3e1bf46cfab0977279105a87bb89adb4c6dac3eb25ea2f300ef3e9aa0a" | bech32 addr_vk
  addr_vk1d5kkc0sm73k04vyhwfu3qk58hwy6mdxxmtp7kf029ucqaulf4g9q8d6yzn

Produce key hashes and compare:
$ cardano-cli address key-hash --payment-verification-key addr_vk1d5kkc0sm73k04vyhwfu3qk58hwy6mdxxmtp7kf029ucqaulf4g9q8d6yzn
ad2704179252c6343d8e27708b725656ec30bc8a347dbb42bfd5509a
$ cardano-cli address key-hash --payment-verification-key-file acct.vkey 
ad2704179252c6343d8e27708b725656ec30bc8a347dbb42bfd5509a


---

