|  Download PASERK Type: PublicExample 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: PublicTypeConstructorpublic function __construct(ProtocolInterface ...$versions): Local;
 The PublicTypeclass accepts multiple protocol versions as constructor arguments.
If not provided, it will default to only supporting Version 4. Class Methodsdecode()
/
 * @param string $paserk
 * @return KeyInterface
 *
 * @throws PaserkException
 */
public function decode(string $paserk): KeyInterface;
 Note: Although the return type declaration is KeyInterface,PublicTypereturns
anAsymmetricPublicKey. encode()
/
 * @param KeyInterface $key
 * @return string
 *
 * @throws PaserkException
 */
public function encode(KeyInterface $key): string;
 Note: Although the type declaration is KeyInterface, you MUST supply aAsymmetricPublicKeyto usePublicTypeserialization. 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. |