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