- var_dump: documentation ( source)
- base64_encode: documentation ( source)
<?php
/**
* Keys taken from the phpecc unit tests, but that library's still vulnerable
* to several side-channels, so don't use it.
*/
$private = '-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIOZ0ioEAxAkAH/7gnZZWIvReXfez9ahXMpOwHzdEkvKcoAcGBSuBBAAK
oUQDQgAE8bjuAc1ucXAA/LbG9i2DSSD8pdgsze34XPD+ddINq3IR/F7TbNvHJdYL
alPIMqm0GJuVB+UGg5duB+921yHYPQ==
-----END EC PRIVATE KEY-----';
$public = '-----BEGIN PUBLIC KEY-----
MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE8bjuAc1ucXAA/LbG9i2DSSD8pdgsze34
XPD+ddINq3IR/F7TbNvHJdYLalPIMqm0GJuVB+UGg5duB+921yHYPQ==
-----END PUBLIC KEY-----';
$privateKey = openssl_pkey_get_private($private);
$publicKey = openssl_pkey_get_public($public);
$data = /* file_get_contents("download.zip")*/ 'Foo bar';
$res = openssl_sign($data, $signature, $privateKey, OPENSSL_ALGO_SHA256);
var_dump(base64_encode($signature));
$ok = openssl_verify($data, $signature, $publicKey, OPENSSL_ALGO_SHA256);
var_dump($ok);