-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathsignMessage.php
36 lines (26 loc) · 959 Bytes
/
signMessage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
require_once '../src/BitcoinPHP/BitcoinECDSA/BitcoinECDSA.php';
use BitcoinPHP\BitcoinECDSA\BitcoinECDSA;
$bitcoinECDSA = new BitcoinECDSA();
$bitcoinECDSA->generateRandomPrivateKey(); //generate new random private key
$message = "Test message";
$signedMessage = $bitcoinECDSA->signMessage($message);
echo "signed message:" . PHP_EOL;
echo $signedMessage . PHP_EOL;
/**
* Will print something like this:
-----BEGIN BITCOIN SIGNED MESSAGE-----
Test message
-----BEGIN SIGNATURE-----
1L56ndSQ1LfrAB2xyo3ZN7egiW4nSs8KWS
HxTqM+b3xj2Qkjhhl+EoUpYsDUz+uTdz6RCY7Z4mV62yOXJ3XCAfkiHV+HGzox7Ba/OC6bC0y6zBX0GhB7UdEM0=
-----END BITCOIN SIGNED MESSAGE-----
*/
// If you only want the signature you can do this
$signature = $bitcoinECDSA->signMessage($message, true);
echo "signature:" . PHP_EOL;
echo $signature . PHP_EOL;
/**
* Will print something like this:
HxTqM+b3xj2Qkjhhl+EoUpYsDUz+uTdz6RCY7Z4mV62yOXJ3XCAfkiHV+HGzox7Ba/OC6bC0y6zBX0GhB7UdEM0=
*/