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

Decode secret is not a valid cert\/public key #97

Open
waynercheung opened this issue Apr 1, 2021 · 1 comment
Open

Decode secret is not a valid cert\/public key #97

waynercheung opened this issue Apr 1, 2021 · 1 comment

Comments

@waynercheung
Copy link

Hi, I've got the "Decode secret is not a valid cert/public key" error.
This is my code:

print("========")
local jwt = require "jwt"
local cjson = require("cjson")

local jwt_token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.OfyWHrVEyPY4JdL5FqWVKdn3Q3tz52Hsd2QK7FLl65hYnO-15bc32ceZTRqbUgLsSnn0nH-hrxM4Es49IFUG6b6eAXMNCAeOiWxtFjuzOVqymx9zwYgHYT4Psk0Furyg6kJFqR5RcYazHkzBL2sbKAQkBp1ln5so3v4YCC4zcI2FaLlvo_jxeJmgQIYZ5amGurzZFvBm_jLrALqzFuXG_YRgUl5_qPGYWThl0rrfdWeqG415uuEstEEjirIPY4j5nfMPJmnsNCpJ0Pm3JMQMazJTL2Uo0sOS-M_NAXzIyNF-53NS0gsswtB5FianU_IRWv4Jm3gr4yghoGIx9_oG2g"

--local public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwewRGFmQrXGUqhAoG8uhZVAZGHTDsgcdmFXu6nPypXJ0A+KDF+c3Z2HUB8syMB9WrL51M0FirJ372MKGOWulQGG2Fvsr9nBxFEIWVMsoIk3HYgiVQNJ+Gnw+2uuunYllyq8NRyReSdN8H4uAekcxEHLTYItKYMo6s6IuVjfIRrbMOqaQuDIM5B5gbyCAd0ODE5ROgw1Kb7N3cewRcQh8JpCNMdHY2xvCVvOwJBxTv+py/2feZGPXmj/aZv15JiISI/JEyKMuDUGVbybx4lNnJNW2MwADgAzZPCVxBy+1pclELx2lPP5HUrzBEESOoNJXxiM68H2sA3pcc7M0SVI7PwIDAQABB"
local public_key = [[MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwewRGFmQrXGUqhAoG8uh
ZVAZGHTDsgcdmFXu6nPypXJ0A+KDF+c3Z2HUB8syMB9WrL51M0FirJ372MKGOWul
QGG2Fvsr9nBxFEIWVMsoIk3HYgiVQNJ+Gnw+2uuunYllyq8NRyReSdN8H4uAekcx
EHLTYItKYMo6s6IuVjfIRrbMOqaQuDIM5B5gbyCAd0ODE5ROgw1Kb7N3cewRcQh8
JpCNMdHY2xvCVvOwJBxTv+py/2feZGPXmj/aZv15JiISI/JEyKMuDUGVbybx4lNn
JNW2MwADgAzZPCVxBy+1pclELx2lPP5HUrzBEESOoNJXxiM68H2sA3pcc7M0SVI7
PwIDAQAB]]

local jwt_obj = jwt:verify(public_key, jwt_token)
ngx.say(cjson.encode(jwt_obj))
return ngx.exit(200)

result:

{"raw_payload":"eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0","raw_header":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9","reason":"Decode secret is not a valid cert\/public key: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwewRGFmQrXGUqhAoG8uh\nZVAZGHTDsgcdmFXu6nPypXJ0A+KDF+c3Z2HUB8syMB9WrL51M0FirJ372MKGOWul\nQGG2Fvsr9nBxFEIWVMsoIk3HYgiVQNJ+Gnw+2uuunYllyq8NRyReSdN8H4uAekcx\nEHLTYItKYMo6s6IuVjfIRrbMOqaQuDIM5B5gbyCAd0ODE5ROgw1Kb7N3cewRcQh8\nJpCNMdHY2xvCVvOwJBxTv+py\/2feZGPXmj\/aZv15JiISI\/JEyKMuDUGVbybx4lNn\nJNW2MwADgAzZPCVxBy+1pclELx2lPP5HUrzBEESOoNJXxiM68H2sA3pcc7M0SVI7\nPwIDAQAB","header":{"typ":"JWT","alg":"RS256"},"valid":true,"verified":false,"payload":{"iat":1516239022,"sub":"1234567890","admin":true,"name":"John Doe"},"signature":"OfyWHrVEyPY4JdL5FqWVKdn3Q3tz52Hsd2QK7FLl65hYnO-15bc32ceZTRqbUgLsSnn0nH-hrxM4Es49IFUG6b6eAXMNCAeOiWxtFjuzOVqymx9zwYgHYT4Psk0Furyg6kJFqR5RcYazHkzBL2sbKAQkBp1ln5so3v4YCC4zcI2FaLlvo_jxeJmgQIYZ5amGurzZFvBm_jLrALqzFuXG_YRgUl5_qPGYWThl0rrfdWeqG415uuEstEEjirIPY4j5nfMPJmnsNCpJ0Pm3JMQMazJTL2Uo0sOS-M_NAXzIyNF-53NS0gsswtB5FianU_IRWv4Jm3gr4yghoGIx9_oG2g"}

Is there any wrong with my code ?

@learner0811
Copy link

You should add -----BEGIN PUBLIC KEY-----<token>\n-----END PUBLIC KEY-----
This work for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants