Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
635 views
in Technique[技术] by (71.8m points)

encryption - Trying to decode JWT Token using PHP-JWT

I'm new in JWT. I can't figure out how to decode JWE token using the PHP-JOSE (https://github.com/nov/jose-php) based on the requirement that stated below.

Requirements:

Our token signing and encryption uses a combination of symmetric and asymmetric algorithms. {Company} uses a nested JWT format structure which signs a JWT and then creates an encrypted JWE with the signed JWT as payload. The token is signed using an RS256 algorithm. The sending party must use their private key to sign the message. The public key of the sending party must be sent over to the receiving party for them to use in the token verification. The encrypted token uses RSA-OAEP algorithm with A128CBC-HS256 as encoding. The key length is 2048 which will be updated to compensate for processor speeds.

To encrypt the token, the sending party must use the receiver's public key. While the receiver must use their own private key to decrypt the message. the Token structure follows JWE format: Header, CEK, initialization vector, encrypted text, and authentication tag. The token is outputted from the platform in serialized compact format. Prior to decryption of the token, if the decryption library used does not automatically pad for the needed base64 padding, then padding must be added. Padding must be added for each token component. If the length mod 4 of the token component is 2, then add two '='. If the length mod 4 is 3, then add one '='.

After decryption of the token, the token can be handled as a normal JWT token with the structure of header, content, and signature.

Sample Response:

enter image description here

This is what I wrote:

$publicKey = "-----BEGIN PUBLIC KEY-----asdaagasd...
              -----END PUBLIC KEY-----";


$jwt_string = $plaintext;
$jwt = JOSE_JWT::decode($jwt_string);
$jws = new JOSE_JWS($jwt);

    

Basing the code in https://github.com/nov/jose-php/blob/master/test/JOSE/JWS_Test.php

function testVerifyRS256() {
        $input = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJmb28iOiJiYXIifQ.GzzxRgDHjgBjDkbMsKaFhWnQ43xKlh8T7Ce34b9ye4afuIfE2EglIlK1itGRx1PtH7UOcwtXVWElJ0lHuuTl6hCUL5SDOMJxiPfr5SkTZFWy2SlSYNtdRfra6NPeEa3-a_15dUYv41QY14TCl5HaP7jeMLeqcTlMcjra9fDPMWUciSyWay6025wUiSQBmWW-19GNZQnRHxXNX3lCVMEQMASYT-6QqBvoiJ6vezIt08RghgGdMH1iGY_Gnb7ISuA-lvKk6fcQvQ3MN5Cx0CeqXlXP8NQQF0OwkUgTjNGsKmCG6jKlLZLeXJb72KVK1yR-6jp7OQqqzrovIP7lp-FwIw';
        $jwt = JOSE_JWT::decode($input);
        $jws = new JOSE_JWS($jwt);
        $this->assertInstanceOf('JOSE_JWS', $jws->verify($this->rsa_keys['public']));
    }

Error:

enter image description here

What should I do to decrypt the code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...