TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Hari Babu
NA
83
0
[Validating JWT token expiry ]
Jan 25 2018 8:36 PM
Hi
I am using visual studio framework 4 and implementing JWT token signature validating and checking time expiry.
i have implemented until Jwt token signature validation but did not find the solution how to check expiry time to jwt token.
Please help me how to check JWT token expiry time.
Code i have implemented
public
string
verifyJWTToken()
{
//string tokenStr = "eyJraWQiOiIxZTlnZGs3IiwiYWxnIjoiUlMyNTYifQ.ewogImlzcyI6ICJodHRwOi8vc2VydmVyLmV4YW1wbGUuY29tIiwKICJzdWIiOiAiMjQ4Mjg5NzYxMDAxIiwKICJhdWQiOiAiczZCaGRSa3F0MyIsCiAibm9uY2UiOiAibi0wUzZfV3pBMk1qIiwKICJleHAiOiAxMzExMjgxOTcwLAogImlhdCI6IDEzMTEyODA5NzAsCiAiY19oYXNoIjogIkxEa3RLZG9RYWszUGswY25YeENsdEEiCn0.XW6uhdrkBgcGx6zVIrCiROpWURs-4goO1sKA4m9jhJIImiGg5muPUcNegx6sSv43c5DSn37sxCRrDZZm4ZPBKKgtYASMcE20SDgvYJdJS0cyuFw7Ijp_7WnIjcrl6B5cmoM6ylCvsLMwkoQAxVublMwH10oAxjzD6NEFsu9nipkszWhsPePf_rM4eMpkmCbTzume-fzZIi5VjdWGGEmzTg32h3jiex-r5WTHbj-u5HL7u_KP3rmbdYNzlzd1xWRYTUs4E8nOTgzAUwvwXkIQhOh5TPcSMBYy6X3E7-_gr9Ue6n4ND7hTFhtjYs3cjNKIA08qm5cpVYFMFMG6PkhzLQ";
string
tokenStr =
"eyAidHlwIjogIkpXVCIsICJhbGciOiAiUlMyNTYiIH0.eyAic3ViI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oJCUu8GBg0RfG85wRKwImPmnPyCoAwqTv2MlqhZQr5oXkkeRrqITkZQME3sFiqZmnExjHcml8Y__5h3FNvJSFdnnZSDW0471wBpYM9-jK7WdBR9rKS68sxdNa85y-TQ7YXcb5AHYPro9GGY6w0"
;
string
[] tokenParts = tokenStr.Split(
'.'
);
X509Certificate2 certificate =
new
X509Certificate2(Path.Combine(@
"C:\Users\haribabu.kommalapati\Downloads\myinfo-demo-app-v1.0\myinfo-demo-app-v1.0\ssl"
,
"stg-auth-signing-public.pem"
));
RSACryptoServiceProvider key = certificate.PublicKey.Key
as
RSACryptoServiceProvider;
RSACryptoServiceProvider rsa =
new
RSACryptoServiceProvider();
if
(key !=
null
)
{
RSAParameters parameters = key.ExportParameters(
false
);
byte
[] expoenet = parameters.Exponent;
byte
[] modulus = parameters.Modulus;
rsa.ImportParameters(
new
RSAParameters()
{
Modulus = modulus,
//FromBase64Url("w7Zdfmece8iaB0kiTY8pCtiBtzbptJmP28nSWwtdjRu0f2GFpajvWE4VhfJAjEsOcwYzay7XGN0b-X84BfC8hmCTOj2b2eHT7NsZegFPKRUQzJ9wW8ipn_aDJWMGDuB1XyqT1E7DYqjUCEOD1b4FLpy_xPn6oV_TYOfQ9fZdbE5HGxJUzekuGcOKqOQ8M7wfYHhHHLxGpQVgL0apWuP2gDDOdTtpuld4D2LK1MZK99s9gaSjRHE8JDb1Z4IGhEcEyzkxswVdPndUWzfvWBBWXWxtSUvQGBRkuy1BHOa4sP6FKjWEeeF7gm7UMs2Nm2QUgNZw6xvEDGaLk4KASdIxRQ"),
Exponent = expoenet
//FromBase64Url("AQAB")
});
}
SHA256 sha256 = SHA256.Create();
byte
[] hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(tokenParts[0] +
'.'
+ tokenParts[1]));
RSAPKCS1SignatureDeformatter rsaDeformatter =
new
RSAPKCS1SignatureDeformatter(rsa);
rsaDeformatter.SetHashAlgorithm(
"SHA256"
);
if
(rsaDeformatter.VerifySignature(hash, FromBase64Url(tokenParts[2])))
{
return
Encoding.UTF8.GetString(Base64UrlDecode(tokenParts[1]));
}
else
{
}
return
string
.Empty;
}
Reply
Answers (
1
)
wcf error cannot obtain metadata from WCF service
Error: Cannot obtain Metadata from WCF service