|  Download PASERK Type: LocalWrapExample code: <?php
use ParagonIE\Paserk\Types\LocalWrap;
use ParagonIE\Paseto\Protocol\Version4;
use ParagonIE\Paseto\Keys\SymmetricKey;
// You first need a wrapping key
$wrappingKey = SymmetricKey::generate(new Version4());
// Next, you can initialize the wrapper
$wrapper = LocalWrap::initWithKey($wrappingKey);
// Finally, you can wrap/unwrap your symmetric keys.
$tempKey = SymmetricKey::generate(new Version4());
$paserk = $wrapper->encode($tempKey);
var_dump($paserk);
$unwrap = $wrapper->decode($paserk);
var_dump(get_class($unwrap));
 Example output: string(146) "k4.local-wrap.pie.b66FQOk3Akt1IbmHT47GDOCtoEpVYmpMxuk7bdsmrbQgskP_zDZXZrYc5nVZrEq2kUWeb9Ni0fkay1A4pSJQ5Y9mLjlJNMfXxASozOgLw_BoD
bbMGl7q5TM8TSfGil-D"
string(34) "ParagonIE\Paseto\Keys\SymmetricKey"
 Class Definition: LocalWrapConstructor/
 * LocalWrap constructor.
 * @param Wrap $wrap
 */
public function __construct(Wrap $wrap): LocalWrap;
 The LocalWrapclass expects a vendor-specificWrapobject to be provided to
its constructor. Currently, the only implementation is one provided by
Paragon Initiative Enterprises. Static MethodsinitWithKey()
/
 * @param SymmetricKey $key
 * @return static
 *
 * @throws InvalidVersionException
 */
public static function initWithKey(SymmetricKey $key): LocalWrap;
 This initializes a LocalWrapwith the defaultWrapimplementation (pie),
passing the providedSymmetricKeyto theWrapinstance, and returns theLocalWrapclass. Class Methodsdecode()
/
 * @throws PaserkException
 */
public function decode(string $paserk): KeyInterface;
 Note: Although the return type declaration is KeyInterface,LocalWrapreturns
aSymmetricKey. encode()
/
 * @param KeyInterface $key
 * @return string
 *
 * @throws InvalidVersionException
 * @throws PaserkException
 */
public function encode(KeyInterface $key): string;
 Note: Although the type declaration is KeyInterface, you MUST supply aSymmetricKeyto useLocalWrapserialization. id()
/
 * @param KeyInterface $key
 * @return string
 *
 * @throws InvalidVersionException
 * @throws PaserkException
 * @throws \SodiumException
 */
public function id(KeyInterface $key): string;
 See Lid. Custom Wrap ProtocolsSee this section for all the supported Wrap implementations. See the PASERK specification
for all the publicly specified custom wrapping protocols. |