Skip to content

The RS256 example just Puzzled me. #225

@miko-cn

Description

@miko-cn

The RS256 example in the readme file can run in my runtime:

  • OpenSSL Library Version: OpenSSL 1.0.2k 26 Jan 2017
  • PHP version: 7.1.9
  • API Framework: ThinkPHP 5.0
$jwt = JWT::encode($token, $privateKey, 'RS256');
$decoded_before_expired = JWT::decode($jwt, $publicKey, array('RS256'));

But when I try to use RS512 publicKey/privateKey in the example without any changes in the code, it just run as perfect as with the RS256 keys of the example which means I still use the RS256 mode to encode and decode my jwt!

And when I try to use RS512 mode in the example code like this:

$jwt = JWT::encode($token, $privateKey, 'RS512');
$decoded_before_expired = JWT::decode($jwt, $publicKey, array('RS512'));

The php framework just told me:

DomainException in JWT.php line 201
OpenSSL unable to sign data

        }
        list($function, $algorithm) = static::$supported_algs[$alg];
        switch($function) {
            case 'hash_hmac':
                return hash_hmac($algorithm, $msg, $key, true);
            case 'openssl':
                $signature = '';
                $success = openssl_sign($msg, $signature, $key, $algorithm);
                if (!$success) {
                    throw new DomainException("OpenSSL unable to sign data");
                } else {
                    return $signature;
                }
        }
    }

    /**
     * Verify a signature with the message, key and method. Not all methods
     * are symmetric, so we must have a separate verify and sign method.

All fine in the RS256 mode, did I misunderstand something here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions