Update objects to use __toString()
This commit is contained in:
@@ -14,8 +14,8 @@
|
||||
namespace Leenooks;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use phpseclib\Crypt\RSA as Crypt_RSA;
|
||||
|
||||
use phpseclib\Crypt\RSA as Crypt_RSA;
|
||||
use Leenooks\OpenPGP\Exceptions\PacketTagException;
|
||||
|
||||
/**
|
||||
@@ -26,6 +26,8 @@ class OpenPGP
|
||||
const VERSION = [0,5,0];
|
||||
private $key = NULL;
|
||||
|
||||
// Functions
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-12.2
|
||||
*/
|
||||
@@ -97,12 +99,18 @@ class OpenPGP
|
||||
return ((int)16 + ($c & 15)) << (($c >> 4) + 6);
|
||||
}
|
||||
|
||||
public function decrypt($data)
|
||||
{
|
||||
$decryptor = new OpenPGP\Crypt\RSA($this->key);
|
||||
return $decryptor->decrypt($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-6
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-6.2
|
||||
* @see http://tools.ietf.org/html/rfc2045
|
||||
*/
|
||||
static function enarmor($data,$marker='MESSAGE',array $headers=[])
|
||||
static function enarmor1($data,$marker='MESSAGE',array $headers=[])
|
||||
{
|
||||
$text = self::header($marker)."\n";
|
||||
|
||||
@@ -117,6 +125,16 @@ class OpenPGP
|
||||
return $text;
|
||||
}
|
||||
|
||||
protected function enarmor(string $data,$marker='MESSAGE',array $headers=[]): string
|
||||
{
|
||||
return static::enarmor1($data,$marker,$headers);
|
||||
}
|
||||
|
||||
public function encrypt(OpenPGP\LiteralDataPacket $data)
|
||||
{
|
||||
return OpenPGP\Crypt\Symmetric::encrypt($this->key,new OpenPGP\Message([$data]));
|
||||
}
|
||||
|
||||
static function encode_s2k_count($iterations)
|
||||
{
|
||||
if($iterations >= 65011712) return 255;
|
||||
@@ -153,6 +171,42 @@ class OpenPGP
|
||||
return '-----BEGIN '.strtoupper((string)$marker).'-----';
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
static function load(string $data,$marker='MESSAGE',bool $binary=TRUE): self
|
||||
{
|
||||
$result = new self;
|
||||
|
||||
$result->key = OpenPGP\Message::parse(
|
||||
$binary ? $data : OpenPGP::unarmor($data,$marker)
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function private(): string
|
||||
{
|
||||
return $this->enarmor((string)$this->key,'PRIVATE KEY');
|
||||
}
|
||||
|
||||
protected function publicKey(): OpenPGP\PublicKeyPacket
|
||||
{
|
||||
return $this->key[0];
|
||||
}
|
||||
|
||||
public function public(): string
|
||||
{
|
||||
return $this->enarmor((string)$this->publicKey(),'PUBLIC KEY');
|
||||
}
|
||||
|
||||
public function signatures()
|
||||
{
|
||||
return $this->key->signatures();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-6
|
||||
* @see http://tools.ietf.org/html/rfc2045
|
||||
@@ -170,4 +224,10 @@ class OpenPGP
|
||||
return base64_decode($text=substr($text,$pos1,$pos2-$pos1));
|
||||
}
|
||||
}
|
||||
|
||||
public function verify(OpenPGP\Message $data)
|
||||
{
|
||||
$verify = new OpenPGP\Crypt\RSA($this->key);
|
||||
return $verify->verify($data);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user