43 lines
1.1 KiB
PHP
Executable File
43 lines
1.1 KiB
PHP
Executable File
<?php
|
|
class SignedCommunicationProvider
|
|
{
|
|
|
|
protected $GPG;
|
|
|
|
public function __construct($keyFile, $fingerprint = null, $passphrase = null, $tmpPath = null)
|
|
{
|
|
if(empty($tmpPath)) {
|
|
$tmpPath = "/tmp/tononixOS.gpg";
|
|
}
|
|
if (file_exists($tmpPath)) {
|
|
unlink($tmpPath);
|
|
}
|
|
$this->GPG = new GnuPG(['home-dir' => $tmpPath]);
|
|
$keyData = file_get_contents($keyFile);
|
|
$this->GPG->import($keyData);
|
|
if (!empty($fingerprint)) {
|
|
$result = $this->GPG->addsignkey($fingerprint, $passphrase);
|
|
if ($result == false) {
|
|
return false;
|
|
} else {
|
|
$this->GPG->setsignmode(GNUPG_SIG_MODE_NORMAL);
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function sign($data)
|
|
{
|
|
if ($this->GPG == null) {
|
|
return false;
|
|
}
|
|
$data = $this->GPG->sign($data);
|
|
return $data;
|
|
}
|
|
|
|
public function verify($data)
|
|
{
|
|
// Verification of signed data should be here.
|
|
}
|
|
}
|