kelvinmo/simplejwt

JWE problem

dcriado1985 opened this issue · 2 comments

Hi!, i have a encript<->decrypt JWE problem, when i try to decrypt tell me "Key not found or is invalid".

public function encodePin($pin){
$stripe=json_decode(file_get_contents('url'));
$set = new SimpleJWT\Keys\KeySet();
$key=new SimpleJWT\Keys\RSAKey(json_encode($stripe->jwk), 'json');
$key->setKeyId($stripe->key_id);
$set->add($key);
$headers = ['alg' => 'RSA-OAEP', 'enc' => 'A128CBC-HS256'];
$jwt = new SimpleJWT\JWE($headers, $pin);
try {
return $jwt->encrypt($set);
} catch (Exception $e) {
return ['status'=>'ko','error'=>$e->getMessage()];
}
}
The url gets me a json similar:
{
"key_id": "xxxxxx",
"pkcs8": "xxxxxxx",
"jwk": {
"kty": "RSA",
"kid": "xxxx",
"use": "enc",
"n": "xxxx",
"e": "AQAB"
}
}

When i try to decode return me "Key not found or is invalid".
public function decodePin($token){
$stripe=json_decode(file_get_contents('url'));
$set = new SimpleJWT\Keys\KeySet();
$key=new SimpleJWT\Keys\RSAKey(json_encode($stripe->jwk), 'json');
$key->setKeyId($stripe->key_id);
$set->add($key);
try {
$jwt = SimpleJWT\JWE::decrypt($token, $set, 'RSA-OAEP');
printr($jwt);
printr ($jwt->getHeader('alg'));
printr ($jwt->getPlaintext());
} catch (\RuntimeException $e) {
printr ($e->getMessage());
}
}
Thanks for help.

In order to decrypt a JWE, you need a private RSA key. The JWK shown appears to be a public RSA key only.

This issue was closed because it has been inactive for 14 days since being marked as stale.