小编Woo*_*row的帖子

在 PHP 中生成 Paseto V2 公钥/令牌,在 Node.js 中验证

前言:

什么是 Paseto?:https : //developer.okta.com/blog/2019/10/17/a-thorough-introduction-to-paseto

  • 我从这里使用 Paseto 的 PHP 库
  • 我正在使用这里的 Node.js Paseto 库

我已经能够使用PHP lib成功实现创建Paseto V1令牌和相应的公钥(在服务器端使用RSA私钥进行密钥对),然后使用公钥在节点上验证给定的令牌.js 方面:

PHP Paseto Public V1:

    $privateKeyV1 = new AsymmetricSecretKey($rsaPrivate, new Version1());
    $publicKeyV1  = $privateKeyV1->getPublicKey();

    $token = (string) (new Builder())
        ->setKey($privateKeyV1)
        ->setVersion(new Version1())
        ->setPurpose(Purpose::public())
        // Set it to expire in one day
        ->setExpiration(
            (new DateTime())->add(new DateInterval('P01D'))
        )
        ->setAudience('Foo')
        ->setIssuedAt(new DateTime())
        ->setIssuer('Bar')
        ->setNotBefore()
        ->setSubject('IDP Paseto')
        ->setClaims([
            'claim' => json_decode($this->claimJSON(), true),
        ])->toString();

    return $response->withJson([
       'public_key_v1' => $publicKeyV1->raw(), 
       'token' => $token
    ]); …
Run Code Online (Sandbox Code Playgroud)

php slim node.js cryptojs paseto

6
推荐指数
1
解决办法
393
查看次数

标签 统计

cryptojs ×1

node.js ×1

paseto ×1

php ×1

slim ×1