Created
September 21, 2022 02:12
-
-
Save badri/226c96a69b8c4cae992958cb91b5843a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local resty_rsa = require "resty.rsa" | |
local codec = require "kong.openid-connect.codec" | |
local base64url = codec.base64url | |
local algorithm = "SHA256" | |
ngx.say('---') | |
-- substitute your "key" here | |
local k = "MHwwDQYJKoZIhvcNAQEBBQADawAwaAJhANGkBcOBvBWEzSfRYErqBpQByj0LMiV6+CTr274ZHlT7rlegHx2AxGK7l2hpl6Da8tJf1sQmHFq7T8bdrR12zB8TvXcLpkkbK6tVverJh+bGqbSqjDZPoRuhvZdpDb6ziQIDAQAB" | |
local orig_rsa_public_key = "-----BEGIN PUBLIC KEY-----\n" .. k .. "\n-----END PUBLIC KEY-----" | |
ngx.say(orig_rsa_public_key) | |
local pub, err = resty_rsa:new({ public_key = orig_rsa_public_key, key_type = resty_rsa.KEY_TYPE.PKCS8, algorithm = algorithm }) | |
if not pub then | |
ngx.say("new rsa err: ", err) | |
return | |
end | |
-- JWT token = "header.payload.signature" | |
-- Add your signature part of the JWT here | |
local sig = "BzdEm_aiFbA6k-VXoAg8wCjJ009UMg3NilywfyyyhnwCmfggZPQIdiNBqm6hXBxlG4jTpn0fEnhDOb2Mo1OKIKMygFxZP_Rm_gaEsqvi7B_G7Vel7wcaCx2z82HDxttq" | |
-- This is your "header.payload" part of the JWT | |
local str = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjIzMDQ5ODE1MWMyMTRiNzg4ZGQ5N2YyMmI4NTQxMGE1In0.eyJzb21lIjoicGF5bG9hZCJ9" | |
local s, err = base64url.decode(sig) | |
if not s then | |
ngx.say("rs signature could not be base64 decoded", err) | |
end | |
local verify, err = pub:verify(str, s) | |
if not verify then | |
ngx.say("verify err: ", err) | |
return | |
end | |
ngx.say(verify) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment