Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with method sign for String #171

Closed
jmjurado23 opened this issue Sep 21, 2016 · 4 comments
Closed

Error with method sign for String #171

jmjurado23 opened this issue Sep 21, 2016 · 4 comments

Comments

@jmjurado23
Copy link

The error is:
undefined method `sign' for #String:0x00000002fbbb78

In line:
def sign_rsa(algorithm, msg, private_key)
private_key.sign(OpenSSL::Digest.new(algorithm.sub('RS', 'sha')), msg)
end

In file: jwt.rb 35

String class (private_key) not have sign method.

What is the problem?

@excpt
Copy link
Member

excpt commented Sep 21, 2016

Can you please provide example code? It looks like the RSA key is no present.

@jmjurado23
Copy link
Author

The code is simply,

pem = '-----BEGIN RSA PRIVATE KEY----- MIKCAQEAiqv0K2dMkuLyuZQiw4j8r7VQjP3zS+nUDgu80tfYA3usRGxx G8DmQDBWIi6MOj80K7nm0f+QcVaztN6NVgw07XaEg8sJ Yg16qULCO4nUhWcVnOaA1YdUC6bZ/DcA pfzPCDEpXT6Nwbj5uJs .... ----- END RSA PRIVATE KEY -----'
params = {
''body": 'example'
}

JWT.encode( params, pem, 'RS256')

And this give me the error, look like String class not have sign method

@jmjurado23
Copy link
Author

I've discovered the error, key should be a OpenSSL::PKey::RSA instance.

Sorry for inconvenences.

@excpt
Copy link
Member

excpt commented Sep 21, 2016

Okay. But I think to improve the experience working with ruby jwt a better error should be displayed.

"The given key is a #{private_key.class}. It has to be an OpenSSL::PKey::RSA instance."

@excpt excpt added this to the Version 1.6.0 milestone Sep 21, 2016
@excpt excpt reopened this Sep 21, 2016
excpt added a commit that referenced this issue Nov 30, 2016
…_error

Add user friendly encode error if private key is a String, #171
@excpt excpt closed this as completed Nov 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants