DownloadPASERK Type: Public
Example code:
<?php
use ParagonIE\Paserk\Types\PublicType;
use ParagonIE\Paseto\Protocol\Version4;
use ParagonIE\Paseto\Keys\AsymmetricPublicKey;
use ParagonIE\Paseto\Keys\AsymmetricSecretKey;
// First, instantiate a `PublicType` object with a given PASETO version.
$encoder = new PublicType(new Version4());
// Now you can serialize/deserialize PASETO AsymmetricPublicKey objects.
$exampleSecretKey = AsymmetricSecretKey::generate(new Version4());
$examplePublicKey = $exampleSecretKey->getPublicKey();
$paserk = $encoder->encode($examplePublicKey);
var_dump($paserk);
// Later, you can get your AsymmetricPublicKey back using the same encoder:
$loaded = $encoder->decode($paserk);
var_dump(get_class($loaded));
Example output:
string(53) "k4.public._kbdHXizFdv0Vhw3PKaDyWuC-9B2-XHwTwqw0TCVfCw"
string(41) "ParagonIE\Paseto\Keys\AsymmetricPublicKey"
Class Definition: PublicType
Constructor
public function __construct(ProtocolInterface ...$versions): Local;
The PublicType class accepts multiple protocol versions as constructor arguments.
If not provided, it will default to only supporting Version 4.
Class Methods
decode()
/
* @param string $paserk
* @return KeyInterface
*
* @throws PaserkException
*/
public function decode(string $paserk): KeyInterface;
Note: Although the return type declaration is KeyInterface , PublicType returns
an AsymmetricPublicKey .
encode()
/
* @param KeyInterface $key
* @return string
*
* @throws PaserkException
*/
public function encode(KeyInterface $key): string;
Note: Although the type declaration is KeyInterface , you MUST supply a
AsymmetricPublicKey to use PublicType serialization.
id()
/
* Get the pid PASERK for the PASERK representation of this local key.
*
* @param KeyInterface $key
* @return string
* @throws PaserkException
* @throws \SodiumException
*/
public function id(KeyInterface $key): string;
See Pid.
|