Skip to content
ecdsa.com
Bitcoin Core RPCWeb3 wallets and signatures

Error message

Malformed base64 encoding

Also printed as

  • error code: -3 error message: Malformed base64 encoding

`bitcoin-cli` prints "error code: -3" and "error message:" before the text. A well-formed base64 string that is not a valid signature returns `false` instead of an error.

Bitcoin Core RPC — verifymessage with a signature that is not base64

What it means

`verifymessage` expects the 65-byte compact signature encoded in standard base64 (88 characters, usually starting with `H`, `I`, `G` or `J`). The string you passed is not valid base64, so Core did not even try to recover a key and returned RPC error -3. The signature may be correct — it is in the wrong text encoding.

Why it happens

How to fix it

  1. 1.

    Convert hex signatures to base64

    Decode the hex to 65 bytes and encode them in standard base64 without line breaks.

    bash
    sig_b64=$(printf '%s' "$SIG_HEX" | xxd -r -p | base64 -w0)   # 65 bytes -> 88 base64 characters
    bitcoin-cli verifymessage "$ADDRESS" "$sig_b64" "$MESSAGE"
  2. 2.

    Undo URL and base64url encoding

    Decode percent-encoding first, then convert base64url to standard base64 with padding.

    python
    import base64, urllib.parse
    
    sig = urllib.parse.unquote(sig_from_query)                     # undo %2B / %2F / %3D
    sig = base64.b64encode(base64.urlsafe_b64decode(sig + "=" * (-len(sig) % 4))).decode()  # base64url -> base64

Related errors

Browse the full signature error database