1. Go to this page and download the library: Download starkbank/ecdsa library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
starkbank / ecdsa example snippets
# Generate privateKey from PEM string
$privateKey = EllipticCurve\PrivateKey::fromPem("
-----BEGIN EC PARAMETERS-----
BgUrgQQACg==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIODvZuS34wFbt0X53+P5EnSj6tMjfVK01dD1dgDH02RzoAcGBSuBBAAK
oUQDQgAE/nvHu/SQQaos9TUljQsUuKI15Zr5SabPrbwtbfT/408rkVVzq8vAisbB
RmpeRREXj5aog/Mq8RrdYy75W9q/Ig==
-----END EC PRIVATE KEY-----
");
# Create message from json
$message = array(
"transfers" => array(
array(
"amount" => 100000000,
"taxId" => "594.739.480-42",
"name" => "Daenerys Targaryen Stormborn",
"bankCode" => "341",
"branchCode" => "2201",
"accountNumber" => "76543-8",
"tags" => array("daenerys", "targaryen", "transfer-1-external-id")
)
)
);
$message = json_encode($message, JSON_PRETTY_PRINT);
$signature = EllipticCurve\Ecdsa::sign($message, $privateKey);
# Generate Signature in base64. This result can be sent to Stark Bank in header as Digital-Signature parameter
echo "\n" . $signature->toBase64();
# To double check if message matches the signature
$publicKey = $privateKey->publicKey();
echo "\n" . EllipticCurve\Ecdsa::verify($message, $signature, $publicKey);
# Generate new Keys
$privateKey = new EllipticCurve\PrivateKey;
$publicKey = $privateKey->publicKey();
$message = "My test message";
# Generate Signature
$signature = EllipticCurve\Ecdsa::sign($message, $privateKey);
# Verify if signature is valid
echo "\n" . EllipticCurve\Ecdsa::verify($message, $signature, $publicKey);