|  Download PASERK Type: SecretWrapExample code: <?php
use ParagonIE\Paserk\Types\SecretWrap;
use ParagonIE\Paseto\Protocol\Version4;
use ParagonIE\Paseto\Keys\AsymmetricSecretKey;
use ParagonIE\Paseto\Keys\SymmetricKey;
// You first need a wrapping key
$wrappingKey = SymmetricKey::generate(new Version4());
// Next, you can initialize the wrapper
$wrapper = SecretWrap::initWithKey($wrappingKey);
// Finally, you can wrap/unwrap your asymmetric secret keys.
$tempKey = AsymmetricSecretKey::generate(new Version4());
$paserk = $wrapper->encode($tempKey);
var_dump($paserk);
$unwrap = $wrapper->decode($paserk);
var_dump(get_class($unwrap));
 Example output: string(190) "k4.secret-wrap.pie.qLi63IiwlxcmggIwyX-jCAxu-irkMXWzRHUxYDoqJqCPy3B81y2THFSKrpg1860DUWN53lkdcsBeEsQbwlxaSFkgSdtxLS7TBz5opmt6Z-Wn
jRcpAlo2NtUMjFLFArR0GdRh_uxGkp6hA5dxlXMcaJAvJnhLVbjCkJFeH71R67E"
string(41) "ParagonIE\Paseto\Keys\AsymmetricSecretKey"
 Class Definition: SecretWrapConstructor/
 * SecretWrap constructor.
 * @param Wrap $wrap
 */
public function __construct(Wrap $wrap): SecretWrap;
 The SecretWrapclass 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): SecretWrap;
 This initializes a SecretWrapwith the defaultWrapimplementation (pie),
passing the providedSymmetricKeyto theWrapinstance, and returns theSecretWrapclass. Class Methodsdecode()
/
 * @throws PaserkException
 */
public function decode(string $paserk): KeyInterface;
 Note: Although the return type declaration is KeyInterface,SecretWrapreturns
anAsymmetricSecretKey. 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 aAsymmetricSecretKeyto useSecretWrapserialization. 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. |