JSON Web Tokens Simple Learning

Source: Internet
Author: User

JWT is used to encrypt a token that generates secure authentication, and to store some user information that is successful in login verification

I. Installation of JWT

    

II. Encryption and decryption code

  

 /*information stored in an encrypted string*/            varPayload =Newdictionary<string,Object> {                { "UserName","Test"},                { "Sex"," Boy"}            }; //secret key            varSecretkey =New byte[] {164, -,194,0,161, A, -, the, the,141,164, $, the,159,209, the,137,243,216,191,131, -, -, +,107,231,117,Panax Notoginseng,158,225,234 }; stringtoken =Jose.JWT.Encode (payload, Secretkey, jwsalgorithm.hs256); Console.WriteLine ("token obtained by encryption:"+token); stringJSON =JWT.            Decode (token, secretkey); Console.WriteLine ("decrypt the resulting string:"+JSON); Console.ReadLine ();

Operation Result:

Encrypted tokens are divided into three parts: header head, Payload payload, Signature signature

1. The token type stored in the head and the encryption algorithm used are BASE64URL encoded

  

2, the load storage is the user information, identification, using the Base64url encoding.

3. Signature is signed using the signature algorithm specified in the header, and the signature is used for the sender of the message and the message has not been tampered with.

Summary: JWT encryption Individuals think that the Base64url encoding is not safe enough for the head and the payload to use.

  

JSON Web Tokens Simple Learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.