<p>A bit late but I created a PHP library for cryptocurrency. You can use <a href="https://github.com/ItayRosen/cryptophp/" rel="nofollow noreferrer">this library</a> to achieve what you want.</p>

<p>You can use it like this:</p>

<pre><code>require('CryptoPHP.php');
$wif_key = 'Kzy3fea4xCwLczAj3g8TYvDw6QRKCMqvVZX2J7vaXgy78VhieRdV'; //this is your wif key
$private_key = $this -&gt; wif2key($wif_key); //get the wif key to a hex private key
$hash = 'Just a sample text'; //this is what you're trying to sign.

$signature = $this -&gt; sign($hash,$private_key);
</code></pre>

CC BY-SA 4.0
2019-01-28T18:38:22.087Z
Not working. Throwing Fatal Error.
Midnight Engineer
CC BY-SA 4.0
2019-01-30T08:15:37.253Z
What error are you getting?
user2298995
CC BY-SA 4.0
2019-01-30T11:52:59.653Z
Fatal error: Using $this when not in object context in sign_message.php on line 4.  

sign_message.php contains your code.
Midnight Engineer
CC BY-SA 3.0
2018-01-07T13:18:58.220Z
2018-01-07T13:18:58.220Z
user2298995
<p>I have the following...</p>

<p><strong>Bitcoin Address</strong>: 1H2zzoAncRcQYihgTMYtX55ioXYErmYQQC</p>

<p><strong>Public Key</strong>: 021FE07FBBB27AD176F1E082950474CD6252FB86751B893BC0887962B008830798</p>

<p><strong>WIF Key</strong>: Kzy3fea4xCwLczAj3g8TYvDw6QRKCMqvVZX2J7vaXgy78VhieRdV</p>

<p><strong>HEX Key</strong>: 6FCE4A50EA529B2D4B3E9671B5B0AA0D5D19266D778FB005F25AE4599D5D2BA0</p>

<p><strong>I need to sign</strong>: Just a sample text</p>

<p><strong>I want this result</strong>: <em>H9saC8UiO0n++3dHZev/apRXkQCrqFofvW9vMpzWqPKsYTNvx/4bdtbdcMORGvNblQknT34UErnwEM3fxTZII0U=</em></p>

<p>How can I code it only in PHP without calling any API or invoking any JS library?</p>

CC BY-SA 3.0
2017-08-16T01:02:27.350Z
The ultimate documentation is the Bitcoin Core source code.  So the short answer to your question is: read their code and reimplement in your language.
Nate Eldredge
CC BY-SA 3.0
2018-03-11T01:20:02.367Z
BTW, **never** use this address for anything ever again since the priv key is published.
Willtech
<signature><php><pgp>
Can I sign a text with a Bitcoin address using PHP only?
Midnight Engineer
# Can I sign a text with a Bitcoin address using PHP only?

(Asked by: username_0 on 2017-08-16)

I have the following...

**Bitcoin Address**: 1H2zzoAncRcQYihgTMYtX55ioXYErmYQQC

**Public Key**: 021FE07FBBB27AD176F1E082950474CD6252FB86751B893BC0887962B008830798

**WIF Key**: Kzy3fea4xCwLczAj3g8TYvDw6QRKCMqvVZX2J7vaXgy78VhieRdV

**HEX Key**: 6FCE4A50EA529B2D4B3E9671B5B0AA0D5D19266D778FB005F25AE4599D5D2BA0

**I need to sign**: Just a sample text

**I want this result**: *H9saC8UiO0n++3dHZev/apRXkQCrqFofvW9vMpzWqPKsYTNvx/4bdtbdcMORGvNblQknT34UErnwEM3fxTZII0U=*

How can I code it only in PHP without calling any API or invoking any JS library?

**Tags:** signature, php, pgp

> **Comments:**
> **username_1**: The ultimate documentation is the Bitcoin Core source code.  So the short answer to your question is: read their code and reimplement in your language.  
> **username_2**: BTW, **never** use this address for anything ever again since the priv key is published.  

---

## 1 answers

### Answer by username_3 on 2018-01-07. Score: 2

A bit late but I created a PHP library for cryptocurrency. You can use this library to achieve what you want.
You can use it like this:
require('CryptoPHP.php');
$wif_key = 'Kzy3fea4xCwLczAj3g8TYvDw6QRKCMqvVZX2J7vaXgy78VhieRdV'; //this is your wif key
$private_key = $this -> wif2key($wif_key); //get the wif key to a hex private key
$hash = 'Just a sample text'; //this is what you're trying to sign.

$signature = $this -> sign($hash,$private_key);

> **Comments:**
> **username_0**: Not working. Throwing Fatal Error.  
> **username_3**: What error are you getting?  
> **username_0**: Fatal error: Using $this when not in object context in sign_message.php on line 4.    sign_message.php contains your code.  

---

